Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / test / TableGen / GlobalISelCombinerEmitter / type-inference.td
blobed4e0e411c7afd6039c5bb5fb7ded601d937fb4c
1 // RUN: llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \
2 // RUN:     -gicombiner-debug-typeinfer -combiners=MyCombiner %s 2>&1 >/dev/null | \
3 // RUN: FileCheck %s
5 // Checks reasoning of the inference rules.
7 include "llvm/Target/Target.td"
8 include "llvm/Target/GlobalISel/Combine.td"
10 def MyTargetISA : InstrInfo;
11 def MyTarget : Target { let InstructionSet = MyTargetISA; }
13 // This also checks that the type of a def is preferred when inferring the type
14 // of an immediate.
15 // CHECK:      Rule Operand Type Equivalence Classes for inference_mul_by_neg_one:
16 // CHECK-NEXT:         Groups for __inference_mul_by_neg_one_match_0:             [dst, x]
17 // CHECK-NEXT:         Groups for __inference_mul_by_neg_one_apply_0:             [dst, x]
18 // CHECK-NEXT: Final Type Equivalence Classes: [dst, x]
19 // CHECK-NEXT: INFER: imm 0 -> GITypeOf<$dst>
20 // CHECK-NEXT: Apply patterns for rule inference_mul_by_neg_one after inference:
21 // CHECK-NEXT:   (CodeGenInstructionPattern name:__inference_mul_by_neg_one_apply_0 G_SUB operands:[<def>$dst, (GITypeOf<$dst> 0), $x])
22 def inference_mul_by_neg_one: GICombineRule <
23   (defs root:$dst),
24   (match (G_MUL $dst, $x, -1)),
25   (apply (G_SUB $dst, 0, $x))
28 // CHECK:      Rule Operand Type Equivalence Classes for infer_complex_tempreg:
29 // CHECK-NEXT:         Groups for __infer_complex_tempreg_match_0:                [dst]   [x, y, z]
30 // CHECK-NEXT:         Groups for __infer_complex_tempreg_apply_0:                [tmp2]  [x, y]
31 // CHECK-NEXT:         Groups for __infer_complex_tempreg_apply_1:                [tmp, tmp2]
32 // CHECK-NEXT:         Groups for __infer_complex_tempreg_apply_2:                [dst, tmp]
33 // CHECK-NEXT: Final Type Equivalence Classes: [dst, tmp, tmp2] [x, y, z]
34 // CHECK-NEXT: INFER: MachineOperand $tmp2 -> GITypeOf<$dst>
35 // CHECK-NEXT: INFER: MachineOperand $tmp -> GITypeOf<$dst>
36 // CHECK-NEXT: Apply patterns for rule infer_complex_tempreg after inference:
37 // CHECK-NEXT:   (CodeGenInstructionPattern name:__infer_complex_tempreg_apply_0 G_BUILD_VECTOR operands:[<def>GITypeOf<$dst>:$tmp2, $x, $y])
38 // CHECK-NEXT:   (CodeGenInstructionPattern name:__infer_complex_tempreg_apply_1 G_FNEG operands:[<def>GITypeOf<$dst>:$tmp, GITypeOf<$dst>:$tmp2])
39 // CHECK-NEXT:   (CodeGenInstructionPattern name:__infer_complex_tempreg_apply_2 G_FNEG operands:[<def>$dst, GITypeOf<$dst>:$tmp])
40 def infer_complex_tempreg: GICombineRule <
41   (defs root:$dst),
42   (match (G_MERGE_VALUES $dst, $x, $y, $z)),
43   (apply (G_BUILD_VECTOR $tmp2, $x, $y),
44          (G_FNEG $tmp, $tmp2),
45          (G_FNEG $dst, $tmp))
48 // CHECK:      Rule Operand Type Equivalence Classes for infer_variadic_outs:
49 // CHECK-NEXT:         Groups for  __infer_variadic_outs_match_0:          [x, y]  [vec]
50 // CHECK-NEXT:         Groups for  __infer_variadic_outs_match_1:          [dst, x]
51 // CHECK-NEXT:         Groups for  __infer_variadic_outs_apply_0:          [tmp, y]
52 // CHECK-NEXT:         Groups for  __infer_variadic_outs_apply_1:
53 // CHECK-NEXT: Final Type Equivalence Classes: [tmp, dst, x, y]  [vec]
54 // CHECK-NEXT: INFER: MachineOperand $tmp -> GITypeOf<$dst>
55 // CHECK-NEXT: Apply patterns for rule infer_variadic_outs after inference:
56 // CHECK-NEXT:   (CodeGenInstructionPattern name:__infer_variadic_outs_apply_0 G_FNEG operands:[<def>GITypeOf<$dst>:$tmp, $y])
57 // CHECK-NEXT:   (CodeGenInstructionPattern name:__infer_variadic_outs_apply_1 COPY operands:[<def>$dst, GITypeOf<$dst>:$tmp])
58 def infer_variadic_outs: GICombineRule <
59   (defs root:$dst),
60   (match  (G_UNMERGE_VALUES $x, $y, $vec),
61           (G_FNEG $dst, $x)),
62   (apply (G_FNEG $tmp, $y),
63          (COPY $dst, $tmp))
66 // Check that the type of an immediate is inferred when there is just one
67 // element in the corresponding equivalence class.
68 // CHECK:      Rule Operand Type Equivalence Classes for infer_imm_0:
69 // CHECK-NEXT:   Groups for __infer_imm_0_match_0: [dst]
70 // CHECK-NEXT:   Groups for __infer_imm_0_apply_0: [dst]
71 // CHECK-NEXT: Final Type Equivalence Classes: [dst]
72 // CHECK-NEXT: INFER: imm 1 -> GITypeOf<$dst>
73 // CHECK-NEXT: INFER: imm 2 -> GITypeOf<$dst>
74 // CHECK-NEXT: Apply patterns for rule infer_imm_0 after inference:
75 // CHECK-NEXT:   (CodeGenInstructionPattern name:__infer_imm_0_apply_0 G_ADD operands:[<def>$dst, (GITypeOf<$dst> 1), (GITypeOf<$dst> 2)])
76 def infer_imm_0 : GICombineRule<
77   (defs root:$dst),
78   (match (G_ADD $dst, 0, 3)),
79   (apply (G_ADD $dst, 1, 2))
82 def MyCombiner: GICombiner<"GenMyCombiner", [
83   inference_mul_by_neg_one,
84   infer_complex_tempreg,
85   infer_variadic_outs,
86   infer_imm_0,
87 ]>;