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

Jeffrey Byrnes via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 7 11:21:12 PDT 2025


jrbyrnes wrote:

One possible solution to this problem is to optimize the code involved in address calculations, so that we do not have a recursion depth limit issue

One potential optimization to do this is to convert sequences of and->icmp->select into and->mul

For example

```
%i48 = and i32 %i28, 1
%i.not2 = icmp eq i32 %i48, 0
%i49 = and i32 %i28, 2
%i50 = icmp eq i32 %i49, 0
%i144 = select i1 %i.not2, i32 0, i32 72
%i145 = select i1 %i50, i32 0, i32 144
%i146 = or disjoint i32 %i144, %i145
```

-> 

```
%temp = and i32 %i32, 3
%146 = mul %temp, 72
```

However, you have stated that the constant operands the select instructions are sort of random and do not need to be the same multiple of a given bit (selected by and). Do you have an example of when this optimization would not work -- the constant operands of the selects are not the same multiple of a bit (selected by and)? I would like to see if there is some other common pattern we can leverage, or if this type of solution is not viable.

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


More information about the llvm-commits mailing list