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+2]]:{{[0-9]+}}: error: expected operand 1 of 'GIReplaceReg' to be a name
12 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceReg ?:$dst, (i32 0))'
13 def builtinpat_immop : GICombineRule<
15 (match (COPY $dst, $src)),
16 (apply (GIReplaceReg $dst, (i32 0)))>;
18 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected operand 1 of 'GIReplaceReg' to be a name
19 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceReg ?:$dst, (i32 0):$k)'
20 def builtinpat_namedimmop : GICombineRule<
22 (match (COPY $dst, $src)),
23 (apply (GIReplaceReg $dst, (i32 0):$k))>;
26 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'GIEraseRoot' cannot be used in a 'match' pattern
27 def eraseroot_in_match : GICombineRule<
29 (match (GIEraseRoot):$mi),
30 (apply (COPY $dst, $src))>;
32 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'GIEraseRoot' expected 0 operands, got 1
33 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIEraseRoot ?:$dst)'
34 def eraseroot_ops : GICombineRule<
36 (match (COPY $dst, $src)),
37 (apply (GIEraseRoot $dst), (COPY $dst, $src))>;
39 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: GIEraseRoot must be the only 'apply' pattern
40 def eraseroot_multiapply : GICombineRule<
42 (match (COPY $dst, $src)),
43 (apply (GIEraseRoot), (COPY $dst, $src))>;
45 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: GIEraseRoot can only be used if on roots that do not have any output operand
46 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: 'COPY' has 1 output operands
47 def eraseroot_root_has_def: GICombineRule<
49 (match (COPY $dst, $src)),
50 (apply (GIEraseRoot))>;
52 def TestPF: GICombinePatFrag<
55 [(pattern (COPY $def, $src))]>;
56 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: GIEraseRoot can only be used if the root is a CodeGenInstruction
57 def eraseroot_notinstmatch: GICombineRule<
59 (match (TestPF $dst):$mi),
60 (apply (GIEraseRoot))>;
62 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'GIReplaceReg' cannot be used in a 'match' pattern
63 def replacereg_in_match : GICombineRule<
65 (match (GIReplaceReg $dst, $src)),
66 (apply (COPY $dst, $src))>;
68 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'GIReplaceReg' expected 2 operands, got 1
69 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceReg ?:$dst)'
70 def replacereg_ops : GICombineRule<
72 (match (COPY $dst, $src)),
73 (apply (GIReplaceReg $dst))>;
75 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: GIReplaceReg cannot replace 'tmp': this builtin can only replace a register defined by the match root
76 def replacereg_nonroot : GICombineRule<
78 (match (COPY $dst, $tmp), (COPY $tmp, $src)),
79 (apply (GIReplaceReg $dst, $src), (GIReplaceReg $tmp, $src))>;
81 // CHECK: error: Failed to parse one or more rules
83 def MyCombiner: GICombiner<"GenMyCombiner", [
85 builtinpat_namedimmop,
89 eraseroot_root_has_def,
90 eraseroot_notinstmatch,