Closed
Description
Alive2 proof: https://alive2.llvm.org/ce/z/Lv9e4r
Description:
define i1 @src(i1 %c1) {
entry:
%c = call i1 @cond()
br i1 %c, label %then, label %else
then:
call void @dummy()
br i1 %c1, label %else, label %return
else:
br label %return
return:
%retval.0 = phi i1 [ true, %else ], [ false, %then ]
ret i1 %retval.0
}
can be folded to:
define i1 @tgt(i1 %c1) {
entry:
%c = call i1 @cond()
br i1 %c, label %then, label %return
then:
call void @dummy()
br i1 %c1, label %else, label %return
else:
br label %return
return:
%retval.0 = phi i1 [ true, %entry ], [ false, %then ], [true, %else]
ret i1 %retval.0
}
The conditional branch in BB entry
can thread directly through nearly empty BB else
to return
.
Real-world motivation
This snippet of IR is derived from auto-generated qemu/xxx/qapi-visit-dump.c (after inline and O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, contact me to get it(Too big to upload here).
Let me know if you can confirm that it's an optimization opportunity, thanks.