1 // RUN: llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \
2 // RUN: -combiners=MyCombiner %s | \
5 include "llvm/Target/Target.td"
6 include "llvm/Target/GlobalISel/Combine.td"
8 def MyTargetISA : InstrInfo;
9 def MyTarget : Target { let InstructionSet = MyTargetISA; }
12 def InstTest0 : GICombineRule<
14 (match (COPY $a, (i32 0))),
15 (apply (COPY $a, 0))>;
17 // implicitly emits a G_CONSTANT
18 def InstTest1 : GICombineRule<
20 (match (G_ZEXT $a, 0)),
21 (apply (COPY $a, (i32 0)))>;
23 // emits a CImm because G_CONSTANT is a special case.
24 def CImmInstTest1 : GICombineRule<
26 (match (G_CONSTANT $a, (i32 0))),
27 (apply (G_CONSTANT $a, (i32 42)))>;
29 def MyCombiner: GICombiner<"GenMyCombiner", [
35 // CHECK: const int64_t *GenMyCombiner::getMatchTable() const {
36 // CHECK-NEXT: constexpr static int64_t MatchTable0[] = {
37 // CHECK-NEXT: GIM_SwitchOpcode, /*MI*/0, /*[*/19, 126, /*)*//*default:*//*Label 3*/ 194,
38 // CHECK-NEXT: /*TargetOpcode::COPY*//*Label 0*/ 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 // CHECK-NEXT: /*TargetOpcode::G_CONSTANT*//*Label 1*/ 138, 0, 0, 0, 0, 0,
40 // CHECK-NEXT: /*TargetOpcode::G_ZEXT*//*Label 2*/ 165,
41 // CHECK-NEXT: // Label 0: @112
42 // CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 4*/ 137, // Rule ID 0 //
43 // CHECK-NEXT: GIM_CheckSimplePredicate, GICXXPred_Simple_IsRule0Enabled,
44 // CHECK-NEXT: GIM_CheckType, /*MI*/0, /*Op*/1, /*Type*/GILLT_s32,
45 // CHECK-NEXT: // MIs[0] a
46 // CHECK-NEXT: // No operand predicates
47 // CHECK-NEXT: GIM_CheckConstantInt, /*MI*/0, /*Op*/1, 0,
48 // CHECK-NEXT: // Combiner Rule #0: InstTest0
49 // CHECK-NEXT: GIR_BuildMI, /*InsnID*/0, /*Opcode*/TargetOpcode::COPY,
50 // CHECK-NEXT: GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/0, // a
51 // CHECK-NEXT: GIR_AddImm, /*InsnID*/0, /*Imm*/0,
52 // CHECK-NEXT: GIR_EraseFromParent, /*InsnID*/0,
53 // CHECK-NEXT: GIR_Done,
54 // CHECK-NEXT: // Label 4: @137
55 // CHECK-NEXT: GIM_Reject,
56 // CHECK-NEXT: // Label 1: @138
57 // CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 5*/ 164, // Rule ID 2 //
58 // CHECK-NEXT: GIM_CheckSimplePredicate, GICXXPred_Simple_IsRule2Enabled,
59 // CHECK-NEXT: GIM_CheckType, /*MI*/0, /*Op*/1, /*Type*/GILLT_s32,
60 // CHECK-NEXT: // MIs[0] a
61 // CHECK-NEXT: // No operand predicates
62 // CHECK-NEXT: GIM_CheckLiteralInt, /*MI*/0, /*Op*/1, 0,
63 // CHECK-NEXT: // Combiner Rule #2: CImmInstTest1
64 // CHECK-NEXT: GIR_BuildMI, /*InsnID*/0, /*Opcode*/TargetOpcode::G_CONSTANT,
65 // CHECK-NEXT: GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/0, // a
66 // CHECK-NEXT: GIR_AddCImm, /*InsnID*/0, /*Type*/GILLT_s32, /*Imm*/42,
67 // CHECK-NEXT: GIR_EraseFromParent, /*InsnID*/0,
68 // CHECK-NEXT: GIR_Done,
69 // CHECK-NEXT: // Label 5: @164
70 // CHECK-NEXT: GIM_Reject,
71 // CHECK-NEXT: // Label 2: @165
72 // CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 6*/ 193, // Rule ID 1 //
73 // CHECK-NEXT: GIM_CheckSimplePredicate, GICXXPred_Simple_IsRule1Enabled,
74 // CHECK-NEXT: // MIs[0] a
75 // CHECK-NEXT: // No operand predicates
76 // CHECK-NEXT: // MIs[0] Operand 1
77 // CHECK-NEXT: GIM_CheckConstantInt, /*MI*/0, /*Op*/1, 0,
78 // CHECK-NEXT: GIR_MakeTempReg, /*TempRegID*/0, /*TypeID*/GILLT_s32,
79 // CHECK-NEXT: GIR_BuildConstant, /*TempRegID*/0, /*Val*/0,
80 // CHECK-NEXT: // Combiner Rule #1: InstTest1
81 // CHECK-NEXT: GIR_BuildMI, /*InsnID*/0, /*Opcode*/TargetOpcode::COPY,
82 // CHECK-NEXT: GIR_Copy, /*NewInsnID*/0, /*OldInsnID*/0, /*OpIdx*/0, // a
83 // CHECK-NEXT: GIR_AddTempRegister, /*InsnID*/0, /*TempRegID*/0, /*TempRegFlags*/0,
84 // CHECK-NEXT: GIR_EraseFromParent, /*InsnID*/0,
85 // CHECK-NEXT: GIR_Done,
86 // CHECK-NEXT: // Label 6: @193
87 // CHECK-NEXT: GIM_Reject,
88 // CHECK-NEXT: // Label 3: @194
89 // CHECK-NEXT: GIM_Reject,
91 // CHECK-NEXT: return MatchTable0;