Alive2 proof: https://alive2.llvm.org/ce/z/-f5J6T
Motivating example
define i32 @src(i1 %c) {
entry:
%cond_zext = zext i1 %c to i32
%s = select i1 %c, i32 67108863, i32 0
%or = or i32 %s, %cond_zext
ret i32 %or
}
can be folded to:
define i32 @tgt(i1 %c) {
entry:
%s = select i1 %c, i32 67108863, i32 0
ret i32 %s
}
Real-world motivation
This snippet of IR is derived from qemu/system/physmem.c@phys_page_set_level (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, please email me.
Let me know if you can confirm that it's an optimization opportunity, thanks.