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 uint8_t *GenMyCombiner::getMatchTable() const {
36 // CHECK-NEXT: constexpr static uint8_t MatchTable0[] = {
37 // CHECK-NEXT: GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(20), GIMT_Encode2({{[0-9]+}}), /*)*//*default:*//*Label 3*/ GIMT_Encode4([[L579:[0-9]+]]),
38 // CHECK-NEXT: /*TargetOpcode::COPY*//*Label 0*/ GIMT_Encode4([[L462:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
39 // CHECK-NEXT: /*TargetOpcode::G_CONSTANT*//*Label 1*/ GIMT_Encode4([[L493:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
40 // CHECK-NEXT: /*TargetOpcode::G_ZEXT*//*Label 2*/ GIMT_Encode4({{[0-9]+}}),
41 // CHECK-NEXT: // Label 0: @[[L462]]
42 // CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 4*/ GIMT_Encode4([[L492:[0-9]+]]), // Rule ID 0 //
43 // CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule0Enabled),
44 // CHECK-NEXT: GIM_RootCheckType, /*Op*/1, /*Type*/GILLT_s32,
45 // CHECK-NEXT: // MIs[0] a
46 // CHECK-NEXT: // No operand predicates
47 // CHECK-NEXT: GIM_CheckConstantInt8, /*MI*/0, /*Op*/1, 0,
48 // CHECK-NEXT: // Combiner Rule #0: InstTest0
49 // CHECK-NEXT: GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(TargetOpcode::COPY),
50 // CHECK-NEXT: GIR_RootToRootCopy, /*OpIdx*/0, // a
51 // CHECK-NEXT: GIR_AddImm8, /*InsnID*/0, /*Imm*/0,
52 // CHECK-NEXT: GIR_EraseRootFromParent_Done,
53 // CHECK-NEXT: // Label 4: @[[L492]]
54 // CHECK-NEXT: GIM_Reject,
55 // CHECK-NEXT: // Label 1: @[[L493]]
56 // CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 5*/ GIMT_Encode4([[L538:[0-9]+]]), // Rule ID 2 //
57 // CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule2Enabled),
58 // CHECK-NEXT: GIM_RootCheckType, /*Op*/1, /*Type*/GILLT_s32,
59 // CHECK-NEXT: // MIs[0] a
60 // CHECK-NEXT: // No operand predicates
61 // CHECK-NEXT: GIM_CheckLiteralInt, /*MI*/0, /*Op*/1, GIMT_Encode8(0),
62 // CHECK-NEXT: // Combiner Rule #2: CImmInstTest1
63 // CHECK-NEXT: GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(TargetOpcode::G_CONSTANT),
64 // CHECK-NEXT: GIR_RootToRootCopy, /*OpIdx*/0, // a
65 // CHECK-NEXT: GIR_AddCImm, /*InsnID*/0, /*Type*/GILLT_s32, /*Imm*/GIMT_Encode8(42),
66 // CHECK-NEXT: GIR_EraseRootFromParent_Done,
67 // CHECK-NEXT: // Label 5: @[[L538]]
68 // CHECK-NEXT: GIM_Reject,
69 // CHECK-NEXT: // Label 2: @{{[0-9]+}}
70 // CHECK-NEXT: GIM_Try, /*On fail goto*//*Label 6*/ GIMT_Encode4([[L578:[0-9]+]]), // Rule ID 1 //
71 // CHECK-NEXT: GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule1Enabled),
72 // CHECK-NEXT: // MIs[0] a
73 // CHECK-NEXT: // No operand predicates
74 // CHECK-NEXT: // MIs[0] Operand 1
75 // CHECK-NEXT: GIM_CheckConstantInt8, /*MI*/0, /*Op*/1, 0,
76 // CHECK-NEXT: GIR_MakeTempReg, /*TempRegID*/0, /*TypeID*/GILLT_s32,
77 // CHECK-NEXT: GIR_BuildConstant, /*TempRegID*/0, /*Val*/GIMT_Encode8(0),
78 // CHECK-NEXT: // Combiner Rule #1: InstTest1
79 // CHECK-NEXT: GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(TargetOpcode::COPY),
80 // CHECK-NEXT: GIR_RootToRootCopy, /*OpIdx*/0, // a
81 // CHECK-NEXT: GIR_AddSimpleTempRegister, /*InsnID*/0, /*TempRegID*/0,
82 // CHECK-NEXT: GIR_EraseRootFromParent_Done,
83 // CHECK-NEXT: // Label 6: @[[L578]]
84 // CHECK-NEXT: GIM_Reject,
85 // CHECK-NEXT: // Label 3: @[[L579]]
86 // CHECK-NEXT: GIM_Reject,
87 // CHECK-NEXT: }; // Size: {{[0-9]+}} bytes
88 // CHECK-NEXT: return MatchTable0;