Alive2 proof: https://alive2.llvm.org/ce/z/NdBYVJ ### Motivating example ```llvm define i32 @src(i64 %addr, i32 %0) { entry: %trunc = trunc i32 %0 to i16 switch i16 %trunc, label %fail [ i16 267, label %common.ret i16 204, label %common.ret i16 263, label %common.ret i16 1, label %sw.bb ] common.ret: ret i32 0 sw.bb: %and75 = and i32 %0, 65535 ret i32 %and75 fail: call void @dummy() br label %common.ret } ``` can be folded to: ```llvm define i32 @tgt(i64 %addr, i32 %0) { entry: %trunc = trunc i32 %0 to i16 switch i16 %trunc, label %fail [ i16 267, label %common.ret i16 204, label %common.ret i16 263, label %common.ret i16 1, label %sw.bb ] common.ret: ret i32 0 sw.bb: ret i32 1 fail: call void @dummy() br label %common.ret } ``` ### Real-world motivation This snippet of IR is derived from [qemu/hw/core/loader.c@load_aout](https://github.com/qemu/qemu/blob/8f3f329f5e0117bd1a23a79ab751f8a7d3471e4b/hw/core/loader.c#L247C13-L247C20) (after O3 pipeline). The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:https://godbolt.org/z/Woa6n1rW1 **Let me know if you can confirm that it's an optimization opportunity, thanks.**