1 // RUN: not llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \
2 // RUN: -combiners=MyCombiner %s 2>&1| \
3 // RUN: FileCheck %s -implicit-check-not=error:
5 include "llvm/Target/Target.td"
6 include "llvm/Target/GlobalISel/Combine.td"
8 def MyTargetISA : InstrInfo;
9 def MyTarget : Target { let InstructionSet = MyTargetISA; }
13 def MatchFooPerms: GICombinePatFrag<
15 (ins gi_mo:$foo, gi_imm:$cst),
17 (pattern "return foo(${foo}, ${cst})"),
18 (pattern "return bar(${foo}, ${cst})"),
19 (pattern "return bux(${foo}, ${cst})"),
22 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: cannot emit rule 'too_many_perms'; 27 permutations would be emitted, but the max is 16
23 let MaxPermutations = 16 in
24 def too_many_perms : GICombineRule<
26 (match (G_ZEXT $dst, $cst),
27 (MatchFooPerms $cst, (i32 0)):$a,
28 (MatchFooPerms $cst, (i32 0)):$b,
29 (MatchFooPerms $cst, (i32 0)):$c
31 (apply (COPY $dst, (i32 0)), "APPLY ${src}")>;
33 def DummyCXXPF: GICombinePatFrag<
37 (pattern "return foo()"),
39 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: operand 'foo' (for parameter 'in' of 'DummyCXXPF') cannot be unbound
40 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: one or more alternatives of 'DummyCXXPF' do not bind 'in' to an instruction operand; either use a bound operand or ensure 'DummyCXXPF' binds 'in' in all alternatives
41 def undef_livein : GICombineRule<
43 (match (G_ZEXT $dst, $bar),
46 (apply (COPY $dst, (i32 0)))>;
48 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: GICombinePatFrag must have one root in its 'out' operands
49 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'OutMustBeRoot'
50 def OutMustBeRoot: GICombinePatFrag<
54 (pattern (G_ZEXT $foo, $bar), (G_FPEXT $bar, $y)),
56 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(OutMustBeRoot ?:$bar, ?:$foo)'
57 def out_must_be_root : GICombineRule<
59 (match (G_ZEXT $dst, $bar),
60 (OutMustBeRoot $bar, $foo)
62 (apply (COPY $dst, (i32 0)))>;
64 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: output parameter 'bar' must be 'root' or 'gi_mo'
65 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'BadOutType'
66 def BadOutType: GICombinePatFrag<
67 (outs root:$foo, gi_imm:$bar),
70 (pattern (G_ZEXT $foo, $bar), (G_FPEXT $bar, $y)),
72 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(BadOutType ?:$bar, ?:$foo)'
73 def bad_out_type : GICombineRule<
75 (match (G_ZEXT $dst, $bar),
76 (BadOutType $bar, $foo)
78 (apply (COPY $dst, (i32 0)))>;
80 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: pattern 'dbg' ('G_FPEXT') is unreachable from the pattern root!
81 def UnreachablePat: GICombinePatFrag<
82 (outs root:$foo, $bar),
85 (pattern (G_ZEXT $foo, $x), (G_FPEXT $bar, $y):$dbg),
87 def unreachable_pat : GICombineRule<
89 (match (G_ZEXT $dst, $bar),
90 (UnreachablePat $bar, $foo)
92 (apply (COPY $dst, (i32 0)))>;
94 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: wip_match_opcode cannot be used in GICombinePatFrag
95 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'WipMatchOpcodePatFrag'
96 def WipMatchOpcodePatFrag: GICombinePatFrag<
100 (pattern (wip_match_opcode G_ZEXT)),
102 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(WipMatchOpcodePatFrag)'
103 def wip_match_opcode_patfrag : GICombineRule<
105 (match (WipMatchOpcodePatFrag)),
106 (apply (COPY $dst, (i32 0)))>;
108 def DummyPF: GICombinePatFrag<(outs),(ins),[]>;
109 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: nested GICombinePatFrag are not supported
110 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'NestingPatFrag'
111 def NestingPatFrag: GICombinePatFrag<
117 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(NestingPatFrag)'
118 def nest_pat_frag : GICombineRule<
120 (match (NestingPatFrag)),
121 (apply (COPY $dst, (i32 0)))>;
123 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: input parameter 'k' cannot be redefined!
124 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'DupParamIn'
125 def DupParamIn: GICombinePatFrag<
127 (ins gi_mo:$k, gi_mo:$k),
129 (pattern (G_ZEXT $k, $x)),
131 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(DupParamIn ?:$dst, ?:$bar)'
132 def dup_params_in : GICombineRule<
134 (match (DupParamIn $dst, $bar)),
135 (apply (COPY $dst, (i32 0)))>;
137 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: duplicate parameter 'k'
138 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'DupParamOut'
139 def DupParamOut: GICombinePatFrag<
140 (outs root:$k, root:$k),
143 (pattern (G_ZEXT $k, $x)),
145 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(DupParamOut ?:$dst, ?:$bar)'
146 def dup_params_out : GICombineRule<
148 (match (DupParamOut $dst, $bar)),
149 (apply (COPY $dst, (i32 0)))>;
151 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: input parameter 'k' cannot be redefined!
152 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'DupParamInOut'
153 def DupParamInOut: GICombinePatFrag<
157 (pattern (G_ZEXT $k, $x)),
159 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(DupParamInOut ?:$dst, ?:$bar)'
160 def dup_params_inout : GICombineRule<
162 (match (DupParamInOut $dst, $bar)),
163 (apply (COPY $dst, (i32 0)))>;
165 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: output parameter 'k' must be defined by all alternative patterns in 'DefByAllAlts'
166 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'DefByAllAlts'
167 def DefByAllAlts: GICombinePatFrag<
171 (pattern (G_ZEXT $k, $x)),
172 (pattern (G_FPEXT $z, $k))
174 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(DefByAllAlts ?:$dst)'
175 def def_by_all_alts : GICombineRule<
177 (match (DefByAllAlts $dst)),
178 (apply (COPY $dst, (i32 0)))>;
180 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: Operand 'x' is defined multiple times in patterns of alternative #1
181 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'MultiDefInPat'
182 def MultiDefInPat: GICombinePatFrag<
186 (pattern (G_ZEXT $k, $a)),
187 (pattern (G_ZEXT $k, $x), (G_ZEXT $x, $foo), (G_FPEXT $x, $foo)),
189 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(MultiDefInPat ?:$dst)'
190 def multi_def_in_pat : GICombineRule<
192 (match (MultiDefInPat $dst)),
193 (apply (COPY $dst, (i32 0)))>;
195 def ExpectedImm: GICombinePatFrag<
199 (pattern (G_ZEXT $k, $i)),
201 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected operand 1 of 'ExpectedImm' to be an immediate; got MachineOperand $z
202 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(ExpectedImm ?:$dst, ?:$z)'
203 def expected_imm : GICombineRule<
205 (match (ExpectedImm $dst, $z)),
206 (apply (COPY $dst, (i32 0)))>;
208 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: operand 1 of 'ExpectedImm' cannot be a named immediate
209 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(ExpectedImm ?:$dst, (i32 0):$z)'
210 def expected_imm_namedimm : GICombineRule<
212 (match (ExpectedImm $dst, (i32 0):$z)),
213 (apply (COPY $dst, (i32 0)))>;
215 def ExpectedMO: GICombinePatFrag<
219 (pattern (G_ZEXT $k, $i)),
221 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected operand 1 of 'ExpectedMO' to be a MachineOperand; got imm 0
222 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(ExpectedMO ?:$dst, (i32 0))'
223 def expected_mo : GICombineRule<
225 (match (ExpectedMO $dst, (i32 0))),
226 (apply (COPY $dst, (i32 0)))>;
227 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected operand 1 of 'ExpectedMO' to be a MachineOperand; got imm 0:$z
228 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(ExpectedMO ?:$dst, (i32 0):$z)'
229 def expected_mo_namedimm : GICombineRule<
231 (match (ExpectedMO $dst, (i32 0):$z)),
232 (apply (COPY $dst, (i32 0)))>;
234 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'dum': using GICombinePatFrag is not supported in apply patterns
235 def patfrag_in_apply : GICombineRule<
237 (match (COPY $dst, (i32 0))),
238 (apply (DummyPF):$dum)>;
240 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: cannot use 'DummyPF as match root
241 def patfrag_cannot_be_root : GICombineRule<
243 (match (DummyPF):$root),
244 (apply (COPY $dst, (i32 0)):$root)>;
246 def TypedParams: GICombinePatFrag<
250 (pattern (G_ZEXT $k, i32:$i)),
252 // CHECK: :[[@LINE+3]]:{{[0-9]+}}: warning: impossible type constraints: operand 1 of 'broken' has type 'i64', but 'TypedParams' constrains it to 'i32'
253 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: note: operand 1 of 'broken' is 'k'
254 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: argument 1 of 'TypedParams' is 'i'
255 def inconsistent_arg_type : GICombineRule<
257 (match (TypedParams $dst, i64:$k):$broken),
258 (apply (COPY $dst, (i32 0)))>;
260 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: all instructions that define root 'foo' in 'RootDefHasMultiDefs' can only have a single output operand
261 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'RootDefHasMultiDefs'
262 def RootDefHasMultiDefs: GICombinePatFrag<
266 (pattern (G_UNMERGE_VALUES $foo, $z, $y))
268 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(RootDefHasMultiDefs ?:$root, (i32 10))'
269 def root_def_has_multi_defs : GICombineRule<
271 (match (RootDefHasMultiDefs $root, (i32 10))),
272 (apply (COPY $root, (i32 0)))>;
274 // CHECK: error: Failed to parse one or more rules
276 def MyCombiner: GICombiner<"GenMyCombiner", [
282 wip_match_opcode_patfrag,
290 expected_imm_namedimm,
292 expected_mo_namedimm,
294 patfrag_cannot_be_root,
295 inconsistent_arg_type,
296 root_def_has_multi_defs