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<
14 (match (COPY $a, $b):$d),
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<
20 (match (COPY $a, $b):$d),
21 (apply (COPY $tmp, $b):$d,
24 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: C++ code cannot be the root of a rule!
25 def cxx_root : GICombineRule<
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<
33 (match (COPY $a, $b)),
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<
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<
47 (match (COPY $a, $b, $c):$d),
50 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Operand 'd' is defined multiple times in the 'match' patterns
51 def multi_defs : GICombineRule<
53 (match (COPY $d, $b), (COPY $d, $x)),
56 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Operand 'd' is defined multiple times in the 'match' patterns
57 def multi_defs_2 : GICombineRule<
59 (match (G_UNMERGE_VALUES $d, $d, $b)),
62 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: pattern 'foo' ('COPY') is unreachable from the pattern root!
63 def unreachable_pat : GICombineRule<
65 (match (COPY $a, $b):$d, (COPY $z, $k):$foo),
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<
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<
77 (match (COPY $a, $b):$d, (wip_match_opcode G_ZEXT)),
80 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: wip_opcode_match can only be present once
81 def multiple_wip_match_opcode : GICombineRule<
83 (match (wip_match_opcode COPY):$d, (wip_match_opcode G_ZEXT)),
86 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Operand 'a' is defined multiple times in the 'apply' patterns
87 def multiple_def_in_apply : GICombineRule<
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<
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<
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<
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<
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<
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<
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<
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<
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<
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<
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<
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<
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<
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<
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<
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)'
192 def bad_mo_type_not_a_valuetype : GICombineRule<
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<
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<
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<
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<
224 (match (G_ZEXT $dst, $src, (MIFlags FmArcp), (MIFlags FmArcp)):$mi),
225 (apply (G_MUL $dst, $src, $src))>;
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<
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<
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<
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<
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<
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", [
276 wip_match_opcode_in_apply,
277 wip_match_opcode_with_inst_pat,
278 multiple_wip_match_opcode,
279 multiple_def_in_apply,
283 cannot_def_match_livein,
286 no_redef_in_apply_multidefroot,
287 instpat_with_wipmatch,
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,
295 bad_mo_type_not_a_valuetype,
296 untyped_new_reg_in_apply,
303 using_flagref_in_match,