Follow up to d0858bffa11, add missing REQUIRES x86
[llvm-project.git] / llvm / test / TableGen / GlobalISelCombinerEmitter / pattern-errors.td
blob318438b977dc953c7cb016bf5c01079663ee90e7
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; }
11 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot find root 'missing' in match patterns!
12 def root_not_found : GICombineRule<
13   (defs root:$missing),
14   (match (COPY $a, $b):$d),
15   (apply [{ APPLY }])>;
17 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: apply pattern 'd' is supposed to be a root but it does not redefine any of the defs of the match root
18 def misleading_root : GICombineRule<
19   (defs root:$d),
20   (match (COPY $a, $b):$d),
21   (apply (COPY $tmp, $b):$d,
22          (COPY $a, $tmp))>;
24 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: C++ code cannot be the root of a rule!
25 def cxx_root : GICombineRule<
26   (defs root:$a),
27   (match "return MATCH":$a),
28   (apply [{ APPLY }]:$z)>;
30 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot use live-in operand 'b' as match pattern root!
31 def livein_root : GICombineRule<
32   (defs root:$b),
33   (match (COPY $a, $b)),
34   (apply [{ APPLY }])>;
36 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'COPY' expected 2 operands, got 1
37 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(COPY ?:$a)'
38 def not_enough_operands : GICombineRule<
39   (defs root:$d),
40   (match (COPY $a):$d),
41   (apply [{ APPLY }])>;
43 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'COPY' expected 2 operands, got 3
44 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(COPY ?:$a, ?:$b, ?:$c)'
45 def too_many_operands : GICombineRule<
46   (defs root:$d),
47   (match (COPY $a, $b, $c):$d),
48   (apply [{ APPLY }])>;
50 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Operand 'd' is defined multiple times in the 'match' patterns
51 def multi_defs : GICombineRule<
52   (defs root:$d),
53   (match (COPY $d, $b), (COPY $d, $x)),
54   (apply [{ APPLY }])>;
56 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Operand 'd' is defined multiple times in the 'match' patterns
57 def multi_defs_2 : GICombineRule<
58   (defs root:$d),
59   (match (G_UNMERGE_VALUES $d, $d, $b)),
60   (apply [{ APPLY }])>;
62 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: pattern 'foo' ('COPY') is unreachable from the pattern root!
63 def unreachable_pat : GICombineRule<
64   (defs root:$d),
65   (match (COPY $a, $b):$d, (COPY $z, $k):$foo),
66   (apply [{ APPLY }])>;
68 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'applytest': wip_match_opcode is not supported in apply patterns
69 def wip_match_opcode_in_apply : GICombineRule<
70   (defs root:$d),
71   (match (COPY $a, $b):$d, (wip_match_opcode G_ZEXT)),
72   (apply (wip_match_opcode G_ZEXT):$applytest)>;
74 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: wip_match_opcode can not be used with instruction patterns!
75 def wip_match_opcode_with_inst_pat : GICombineRule<
76   (defs root:$d),
77   (match (COPY $a, $b):$d, (wip_match_opcode G_ZEXT)),
78   (apply [{ APPLY }])>;
80 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: wip_opcode_match can only be present once
81 def multiple_wip_match_opcode : GICombineRule<
82   (defs root:$d),
83   (match (wip_match_opcode COPY):$d, (wip_match_opcode G_ZEXT)),
84   (apply [{ APPLY }])>;
86 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Operand 'a' is defined multiple times in the 'apply' patterns
87 def multiple_def_in_apply : GICombineRule<
88   (defs root:$d),
89   (match (COPY $a, $b):$d),
90   (apply (COPY $a, $b), (COPY $a, $b))>;
92 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'd' match pattern defined more than once!
93 def redef_match : GICombineRule<
94   (defs root:$d),
95   (match (COPY $a, $b):$d, (COPY $b, $z):$d),
96   (apply (COPY $a, $b))>;
98 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'o' apply pattern defined more than once!
99 def redef_apply: GICombineRule<
100   (defs root:$d),
101   (match (COPY $a, $b):$d),
102   (apply (COPY $a, $x):$o, (COPY $x, $b):$o)>;
104 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: redefining an instruction other than the root is not supported (operand 'b'
105 def redef_nonroot : GICombineRule<
106   (defs root:$a),
107   (match (COPY $a, $b), (COPY $b, $z)),
108   (apply (COPY $a, $b), (G_ZEXT $b, (i32 0)))>;
110 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Cannot define live-in operand 'b' in the 'apply' pattern
111 def cannot_def_match_livein : GICombineRule<
112   (defs root:$d),
113   (match (COPY $a, $b):$d),
114   (apply (COPY $a, $b), (COPY $b, $b))>;
116 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: invalid output operand 'x': operand is not a live-in of the match pattern, and it has no definition
117 def undef_in_apply : GICombineRule<
118   (defs root:$d),
119   (match (COPY $a, $b):$d),
120   (apply (COPY $a, $x))>;
122 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'a' must be redefined in the 'apply' pattern
123 def no_redef_in_apply : GICombineRule<
124   (defs root:$a),
125   (match (COPY $a, $b):$foo),
126   (apply (COPY $x, $b))>;
128 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'b' must be redefined in the 'apply' pattern
129 def no_redef_in_apply_multidefroot : GICombineRule<
130   (defs root:$a),
131   (match (G_UNMERGE_VALUES $a, $b, $c)),
132   (apply (COPY $a, $c))>;
134 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: cannot use wip_match_opcode in combination with apply instruction patterns
135 def instpat_with_wipmatch : GICombineRule<
136   (defs root:$d),
137   (match (wip_match_opcode COPY):$d),
138   (apply (COPY $x, $b):$d)>;
140 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: cannot parse operand '(i32)'
141 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(COPY ?:$x, (i32))
142 def bad_imm_noarg : GICombineRule<
143   (defs root:$a),
144   (match (COPY $x, (i32)):$d),
145   (apply (COPY $x, $b):$d)>;
147 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: cannot parse operand '(i32 0, 0)'
148 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(COPY ?:$x, (i32 0, 0))
149 def bad_imm_too_many_args : GICombineRule<
150   (defs root:$a),
151   (match (COPY $x, (i32 0, 0)):$d),
152   (apply (COPY $x, $b):$d)>;
154 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: cannot parse immediate '(COPY 0)': unknown type 'COPY'
155 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(COPY ?:$x, (COPY 0))
156 def bad_imm_not_a_valuetype : GICombineRule<
157   (defs root:$a),
158   (match (COPY $x, (COPY 0)):$d),
159   (apply (COPY $x, $b):$d)>;
161 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: invalid output operand 'imm': output immediates cannot be named
162 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: while emitting pattern 'd' (COPY)
163 def output_imm_cannot_be_named : GICombineRule<
164   (defs root:$x),
165   (match (COPY $x, (i32 0)):$d),
166   (apply (COPY $x, (i32 0):$imm):$d)>;
168 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'G_CONSTANT' immediate must be typed!
169 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: while emitting pattern 'd' (G_CONSTANT)
170 def output_imm_must_be_typed : GICombineRule<
171   (defs root:$x),
172   (match (COPY $x, (i32 0)):$d),
173   (apply (G_CONSTANT $x, 0):$d)>;
175 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'G_BUILD_VECTOR' expected at least 2 operands, got 1
176 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(G_BUILD_VECTOR ?:$x)'
177 def too_few_ops_for_variadic : GICombineRule<
178   (defs root:$x),
179   (match (G_BUILD_VECTOR $x)),
180   (apply (COPY $x, 0))>;
182 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected an operand name after 'i32'
183 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(G_FNEG ?:$x, i32)'
184 def expected_op_name : GICombineRule<
185   (defs root:$x),
186   (match (G_FNEG $x, i32)),
187   (apply (COPY $x, (i32 0)))>;
189 // CHECK: :[[@LINE+3]]:{{[0-9]+}}: error: cannot parse operand type: unknown type 'not_a_type'
190 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: Failed to parse pattern: '(G_FNEG ?:$x, not_a_type:$y)'
191 def not_a_type;
192 def bad_mo_type_not_a_valuetype : GICombineRule<
193   (defs root:$x),
194   (match (G_FNEG $x, not_a_type:$y)),
195   (apply (COPY $x, (i32 0)))>;
197 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: def of a new register 'newreg' in the apply patterns must have a type
198 def untyped_new_reg_in_apply : GICombineRule<
199   (defs root:$x),
200   (match (G_FNEG $x, $y)),
201   (apply (COPY $newreg, (i32 0)),
202          (COPY $x, $newreg))>;
204 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'y' is a named immediate, it cannot be defined by another instruction
205 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: 'y' is defined by 'foo'
206 def def_named_imm_match : GICombineRule<
207   (defs root:$x),
208   (match  (G_SEXT $y, $z):$foo,
209           (G_FNEG $x, (i32 0):$y)),
210   (apply (COPY $x, (i32 0)))>;
212 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: invalid output operand 'tmp': output immediates cannot be named
213 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: while emitting pattern 'foo' (COPY)
214 def def_named_imm_apply : GICombineRule<
215   (defs root:$x),
216   (match (G_FNEG $x, $y)),
217   (apply (COPY i32:$tmp, $y),
218          (COPY $x, (i32 0):$tmp):$foo)>;
220 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: MIFlags can only be present once on an instruction
221 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(G_ZEXT ?:$dst, ?:$src, (MIFlags FmArcp), (MIFlags FmArcp))'
222 def multi_miflags : GICombineRule<
223   (defs root:$dst),
224   (match (G_ZEXT $dst, $src, (MIFlags FmArcp), (MIFlags FmArcp)):$mi),
225   (apply (G_MUL $dst, $src, $src))>;
227 def NotAMIFlagEnum;
229 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'NotAMIFlagEnum' is not a subclass of 'MIFlagEnum'
230 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(G_ZEXT ?:$dst, ?:$src, (MIFlags NotAMIFlagEnum))'
231 def not_miflagenum_1 : GICombineRule<
232   (defs root:$dst),
233   (match (G_ZEXT $dst, $src, (MIFlags NotAMIFlagEnum)):$mi),
234   (apply (G_MUL $dst, $src, $src))>;
236 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'NotAMIFlagEnum' is not a subclass of 'MIFlagEnum'
237 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(G_ZEXT ?:$dst, ?:$src, (MIFlags (not NotAMIFlagEnum)))'
238 def not_miflagenum_2 : GICombineRule<
239   (defs root:$dst),
240   (match (G_ZEXT $dst, $src, (MIFlags (not NotAMIFlagEnum))):$mi),
242   (apply (G_MUL $dst, $src, $src))>;
244 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: matching/writing MIFlags is only allowed on CodeGenInstruction patterns
245 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceReg ?:$x, ?:$y, (MIFlags FmArcp))'
246 def miflags_in_builtin : GICombineRule<
247   (defs root:$x),
248   (match (COPY $x, $y)),
249   (apply (GIReplaceReg $x, $y, (MIFlags FmArcp)))>;
251 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'match' patterns cannot refer to flags from other instructions
252 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: MIFlags in 'mi' refer to: impostor
253 def using_flagref_in_match : GICombineRule<
254   (defs root:$dst),
255   (match (G_ZEXT $dst, $src, (MIFlags $impostor)):$mi),
256   (apply (G_MUL $dst, $src, $src))>;
258 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: unknown instruction '$impostor' referenced in MIFlags of '__badflagref_in_apply_apply_0'
259 def badflagref_in_apply : GICombineRule<
260   (defs root:$dst),
261   (match (G_ZEXT $dst, $src):$mi),
262   (apply (G_MUL $dst, $src, $src, (MIFlags $impostor)))>;
264 // CHECK: error: Failed to parse one or more rules
266 def MyCombiner: GICombiner<"GenMyCombiner", [
267   root_not_found,
268   misleading_root,
269   cxx_root,
270   livein_root,
271   not_enough_operands,
272   too_many_operands,
273   multi_defs,
274   multi_defs_2,
275   unreachable_pat,
276   wip_match_opcode_in_apply,
277   wip_match_opcode_with_inst_pat,
278   multiple_wip_match_opcode,
279   multiple_def_in_apply,
280   redef_match,
281   redef_apply,
282   redef_nonroot,
283   cannot_def_match_livein,
284   undef_in_apply,
285   no_redef_in_apply,
286   no_redef_in_apply_multidefroot,
287   instpat_with_wipmatch,
288   bad_imm_noarg,
289   bad_imm_too_many_args,
290   bad_imm_not_a_valuetype,
291   output_imm_cannot_be_named,
292   output_imm_must_be_typed,
293   too_few_ops_for_variadic,
294   expected_op_name,
295   bad_mo_type_not_a_valuetype,
296   untyped_new_reg_in_apply,
297   def_named_imm_match,
298   def_named_imm_apply,
299   multi_miflags,
300   not_miflagenum_1,
301   not_miflagenum_2,
302   miflags_in_builtin,
303   using_flagref_in_match,
304   badflagref_in_apply