[llvm] [SimplifyCFG] Fold `switch(zext/sext(X))` into `switch(X)` (PR #76988)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 4 11:12:37 PST 2024


dtcxzyw wrote:

> Why is this in SimplifyCFG? This seems like an extension of the existing switch width fold in InstCombine:
> 
> https://github.com/llvm/llvm-project/blob/8b2bdfbca7c1db272e4e703445f5626b4bc4b9d3/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L3224

IIRC, `InstCombine` cannot change the dominator tree.

See the following case:
```
 define i1 @test_switch_with_sext_unreachable_case(i16 %a, i1 %b, i1 %c) {
 entry:
   %a.ext = sext i16 %a to i32
   switch i32 %a.ext, label %sw.default [
   i32 37, label %sw.bb
   i32 38, label %sw.bb
   i32 39, label %sw.bb
   i32 -65499, label %sw.bb2
   ]

 sw.bb:
   ret i1 %b
 sw.bb2:
   ret i1 false
 sw.default:
   ret i1 %c
 }
```
In this case, the edge `i32 -65499, label %sw.bb2` should be eliminated.



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


More information about the llvm-commits mailing list