[llvm] [SimplifyCFG] Simplify switch default branch when branch proves operand value (PR #206597)
Sayan Sivakumaran via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 12:00:38 PDT 2026
sivakusayan wrote:
Two notes:
- Notice in the test cases that we can't simplify to a lookup table through a single pass of `simplifycfg`, presumably because of the straggling `llvm.assume`. However, it does get converted to a lookup table after running `simplify cfg,gvn,simplifycfg<switch-to-lookup>`. I wasn't sure if we wanted a separate test case for that.
- This doesn't completely fix the linked issue, as the lookup table generated for `conv1` isn't simplified into a single `sext` after the pass pipeline completes. Instead, we are left with the below when compiling for x86-64. However, I think this can be iterated on and is still technically an improvement, as we simplify the CFG considerably.
```
define noundef range(i32 -1, 2) i32 @_Z5conv1NSt3__115strong_orderingE(i8 %s.coerce) local_unnamed_addr #0 {
entry:
%switch.tableidx = add nsw i8 %s.coerce, 1
%switch.idx.cast = zext i8 %switch.tableidx to i32
%switch.offset = add nsw i32 %switch.idx.cast, -1
ret i32 %switch.offset
}
```
Presumably we would need to touch something in InstCombine to use range information to conclude this can be simplified? [(alive)](https://alive2.llvm.org/ce/z/L9Mwej)
https://github.com/llvm/llvm-project/pull/206597
More information about the llvm-commits
mailing list