[llvm] [SLSR] Prove disjoint instruction reuse using an annotation-free IR (PR #218308)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 12 10:17:13 PDT 2026
choi3171 wrote:
In `canReuseInstruction`:
```cpp
// Disjoint or instructions are interpreted as adds by SCEV. However, we
// can't replace an arbitrary add with disjoint or, even if we drop the
// flag. We would need to convert the or into an add.
```
Instead of cloning, turning `or disjoint` into `add` may be a solution. A flag-free `add` cannot be poison, so the rewrite is a refinement.
Also a small public case, reduced from a Triton matmul tile:
```llvm
define i32 @f(i32 %a) {
%s = shl i32 %a, 6
%b1 = or disjoint i32 %s, 60
%m1 = mul i32 %a, %b1
%b2 = or disjoint i32 %s, 56
%m2 = mul i32 %a, %b2
%r = add i32 %m1, %m2
ret i32 %r
}
```
`opt -passes=slsr` keeps both muls; with `-enable-poison-reuse-guard=false`, or with `or disjoint` replaced by `add` in the input, `%m2` becomes `%m1 - (%a << 2)`. This PR recovers the kernel it was reduced from.
However, this is not a small task. Other callers of `canReuseInstruction` (`NaryReassociate`, `SimplifyIndVar`, `VPlanUtils`) would need the same `or` -> `add` conversion. Also there is an exception, `SCEVExpander`: it can restore dropped flags, so I think it would need separate handling.
> Assisted by claude.
https://github.com/llvm/llvm-project/pull/218308
More information about the llvm-commits
mailing list