|
| 1 | +// RUN: llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \ |
| 2 | +// RUN: -gicombiner-debug-typeinfer -combiners=MyCombiner %s 2>&1 | \ |
| 3 | +// RUN: FileCheck %s |
| 4 | + |
| 5 | +// Checks reasoning of the inference rules. |
| 6 | + |
| 7 | +include "llvm/Target/Target.td" |
| 8 | +include "llvm/Target/GlobalISel/Combine.td" |
| 9 | + |
| 10 | +def MyTargetISA : InstrInfo; |
| 11 | +def MyTarget : Target { let InstructionSet = MyTargetISA; } |
| 12 | + |
| 13 | +// CHECK: Rule Operand Type Equivalence Classes for inference_mul_by_neg_one: |
| 14 | +// CHECK-NEXT: __inference_mul_by_neg_one_match_0: [dst, x] |
| 15 | +// CHECK-NEXT: __inference_mul_by_neg_one_apply_0: [dst, x] |
| 16 | +// CHECK-NEXT: (merging [dst, x] | [dst, x]) |
| 17 | +// CHECK-NEXT: Result: [dst, x] |
| 18 | +// CHECK-NEXT: INFER: imm 0 -> GITypeOf<$x> |
| 19 | +// CHECK-NEXT: Apply patterns for rule inference_mul_by_neg_one after inference: |
| 20 | +// CHECK-NEXT: (CodeGenInstructionPattern name:__inference_mul_by_neg_one_apply_0 G_SUB operands:[<def>$dst, (GITypeOf<$x> 0), $x]) |
| 21 | +def inference_mul_by_neg_one: GICombineRule < |
| 22 | + (defs root:$dst), |
| 23 | + (match (G_MUL $dst, $x, -1)), |
| 24 | + (apply (G_SUB $dst, 0, $x)) |
| 25 | +>; |
| 26 | + |
| 27 | +// CHECK: Rule Operand Type Equivalence Classes for infer_complex_tempreg: |
| 28 | +// CHECK-NEXT: __infer_complex_tempreg_match_0: [dst] [x, y, z] |
| 29 | +// CHECK-NEXT: __infer_complex_tempreg_apply_0: [tmp2] [x, y] |
| 30 | +// CHECK-NEXT: __infer_complex_tempreg_apply_1: [tmp, tmp2] |
| 31 | +// CHECK-NEXT: __infer_complex_tempreg_apply_2: [dst, tmp] |
| 32 | +// CHECK-NEXT: (merging [dst] | [dst, tmp]) |
| 33 | +// CHECK-NEXT: (merging [x, y, z] | [x, y]) |
| 34 | +// CHECK-NEXT: (merging [tmp2] | [tmp, tmp2]) |
| 35 | +// CHECK-NEXT: (merging [dst, tmp] | [tmp2, tmp]) |
| 36 | +// CHECK-NEXT: Result: [dst, tmp, tmp2] [x, y, z] |
| 37 | +// CHECK-NEXT: INFER: MachineOperand $tmp2 -> GITypeOf<$dst> |
| 38 | +// CHECK-NEXT: INFER: MachineOperand $tmp -> GITypeOf<$dst> |
| 39 | +// CHECK-NEXT: Apply patterns for rule infer_complex_tempreg after inference: |
| 40 | +// CHECK-NEXT: (CodeGenInstructionPattern name:__infer_complex_tempreg_apply_0 G_BUILD_VECTOR operands:[<def>GITypeOf<$dst>:$tmp2, $x, $y]) |
| 41 | +// CHECK-NEXT: (CodeGenInstructionPattern name:__infer_complex_tempreg_apply_1 G_FNEG operands:[<def>GITypeOf<$dst>:$tmp, GITypeOf<$dst>:$tmp2]) |
| 42 | +// CHECK-NEXT: (CodeGenInstructionPattern name:__infer_complex_tempreg_apply_2 G_FNEG operands:[<def>$dst, GITypeOf<$dst>:$tmp]) |
| 43 | +def infer_complex_tempreg: GICombineRule < |
| 44 | + (defs root:$dst), |
| 45 | + (match (G_MERGE_VALUES $dst, $x, $y, $z)), |
| 46 | + (apply (G_BUILD_VECTOR $tmp2, $x, $y), |
| 47 | + (G_FNEG $tmp, $tmp2), |
| 48 | + (G_FNEG $dst, $tmp)) |
| 49 | +>; |
| 50 | + |
| 51 | +// CHECK: Rule Operand Type Equivalence Classes for infer_variadic_outs: |
| 52 | +// CHECK-NEXT: __infer_variadic_outs_match_0: [x, y] [vec] |
| 53 | +// CHECK-NEXT: __infer_variadic_outs_match_1: [dst, x] |
| 54 | +// CHECK-NEXT: __infer_variadic_outs_apply_0: [tmp, y] |
| 55 | +// CHECK-NEXT: __infer_variadic_outs_apply_1: (empty) |
| 56 | +// CHECK-NEXT: (merging [x, y] | [dst, x]) |
| 57 | +// CHECK-NEXT: (merging [x, y, dst] | [tmp, y]) |
| 58 | +// CHECK-NEXT: Result: [x, y, dst, tmp] [vec] |
| 59 | +// CHECK-NEXT: INFER: MachineOperand $tmp -> GITypeOf<$x> |
| 60 | +// CHECK-NEXT: Apply patterns for rule infer_variadic_outs after inference: |
| 61 | +// CHECK-NEXT: (CodeGenInstructionPattern name:__infer_variadic_outs_apply_0 G_FNEG operands:[<def>GITypeOf<$x>:$tmp, $y]) |
| 62 | +// CHECK-NEXT: (CodeGenInstructionPattern name:__infer_variadic_outs_apply_1 COPY operands:[<def>$dst, GITypeOf<$x>:$tmp]) |
| 63 | +def infer_variadic_outs: GICombineRule < |
| 64 | + (defs root:$dst), |
| 65 | + (match (G_UNMERGE_VALUES $x, $y, $vec), |
| 66 | + (G_FNEG $dst, $x)), |
| 67 | + (apply (G_FNEG $tmp, $y), |
| 68 | + (COPY $dst, $tmp)) |
| 69 | +>; |
| 70 | + |
| 71 | +def MyCombiner: GICombiner<"GenMyCombiner", [ |
| 72 | + inference_mul_by_neg_one, |
| 73 | + infer_complex_tempreg, |
| 74 | + infer_variadic_outs |
| 75 | +]>; |
0 commit comments