[GlobalISel] Tablegen combines are not commutative
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
For example following pattern from `llvm/include/llvm/Target/GlobalISel/Combine.td` will match for first test below but not second which commutes operands on the last G_ADD
```
// fold (A+(B-(A+C))) to (B-C)
def APlusBMinusAplusC : GICombineRule<
(defs root:$root),
(match (G_ADD $add1, $A, $C),
(G_SUB $sub1, $B, $add1),
(G_ADD $root, $A, $sub1)),
(apply (G_SUB $root, $B, $C))>;
```
```$ llc -march=amdgcn -mcpu=gfx1200 -o - -run-pass=amdgpu-prelegalizer-combiner test.mir```
test.mir:
```
---
name: test
body: |
bb.1:
liveins: $vgpr0, $vgpr1, $vgpr2
%A:_(s32) = COPY $vgpr0
%B:_(s32) = COPY $vgpr1
%C:_(s32) = COPY $vgpr2
%add1:_(s32) = G_ADD %A, %C
%sub1:_(s32) = G_SUB %B, %add1
%root:_(s32) = G_ADD %A, %sub1
$vgpr0 = COPY %root(s32)
SI_RETURN implicit $vgpr0
...
---
name: test_rev
body: |
bb.1:
liveins: $vgpr0, $vgpr1, $vgpr2
%A:_(s32) = COPY $vgpr0
%B:_(s32) = COPY $vgpr1
%C:_(s32) = COPY $vgpr2
%add1:_(s32) = G_ADD %A, %C
%sub1:_(s32) = G_SUB %B, %add1
%root:_(s32) = G_ADD %sub1, %A
$vgpr0 = COPY %root(s32)
SI_RETURN implicit $vgpr0
...
```
Contributor guide
Research direction
Start with the APlusBMinusAplusC pattern in llvm/include/llvm/Target/GlobalISel/Combine.td and reproduce the operand-order difference using llc with test.mir. Done means the combine matches both the original and test_rev G_ADD forms.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100