[llvm] [InstCombine] Fold inner selects on the same condition in select values (PR #226371)
Henry Jiang via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 00:09:08 PDT 2026
mustartt wrote:
> LGTM, but it would be helpful if we could make the `isSafelySpeculative` change first in a separate PR to be able to see the impacts of that change vs. the generalization of the instcombine to n-ary ops from binops.
Here is the result https://github.com/dtcxzyw/llvm-opt-benchmark-nightly/pull/1543 for `isSafeToSpeculativelyExecuteWithVariableReplaced`. There is no effect, which make sense since the original `!TrueBO->isIntDivRem()` covers all of the cases.
The additional generalization here is
1. generalizing over `m_OneUse()` as seen here, which is the majority of the patterns replaced.
```
%s = select i1 %c, i32 %a, i32 %b
%i = add i32 %s, 1
%r0 = select i1 %c, i32 %i, i32 %x
%r1 = select i1 %c, i32 %i, i32 %y
; becomes
%i = add i32 %a, 1
%r0 = select i1 %c, i32 %i, i32 %x
%r1 = select i1 %c, i32 %i, i32 %y
```
2. n-ary ops are quite rare, but there are a few cases
https://github.com/llvm/llvm-project/pull/226371
More information about the llvm-commits
mailing list