[llvm] [InstCombine] Canonicalize xor with disjoint ops to or disjoint (PR #133139)

Jeffrey Byrnes via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 2 16:44:16 PDT 2025


jrbyrnes wrote:

> What was the original sequence that exceeds the limit?

See for a representation of the original sequence

https://godbolt.org/z/9rE9dneT9

There is an opportunity for another instcombine in this sequence -- we can transform
```
%i48 = and i32 %i28, 1
%i.not2 = icmp eq i32 %i48, 0
%i144 = select i1 %i.not2, i32 0, i32 72
```

into 
```
%i48 = and %i28, 1
%i144 = mul i32 %i48, 72
```

There are a couple similar patterns combined together with an `or disjoint` -- these can basically be transformed into an `and`->`mul` . There are a couple other more complex opportunities, but I haven't been able to find a way to reduce the depth enough to transform the final `xor` -> `or disjoint` and extract the constant.

I'm leaning towards providing an API to computeKnownBits to override the depth limit, for cases where getting it right is worth a bit more compile time (e.g. separateConstOffsetFromGEP).




https://github.com/llvm/llvm-project/pull/133139


More information about the llvm-commits mailing list