<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/76609>76609</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[JumpThreading] Missing optimization: thread over a nearly empty basicblock
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
XChy
</td>
</tr>
</table>
<pre>
Alive2 proof: https://alive2.llvm.org/ce/z/Lv9e4r
### Description:
```llvm
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:
```llvm
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](https://github.com/qemu/qemu/blob/master/qapi/dump.json) (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:
**Let me know if you can confirm that it's an optimization opportunity, thanks.**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VcGO2zYQ_Rr6MrDBpWzZOviwjiEgRYoCQQ69kuLImoQiFZJS1vn6gpS269202S2KVhAsDzl88zjzOJQh0MUiHtnuxHbnlRxj5_zx93fddaWcvh7vDU0oYPDOtay4hy7GIbDinomaiVrm2Y0xU79x_sJE3SAT9Xcm6g9ThVvP-Jnx--VXFPMLZwyNpyGSswnq1qfk85sg5yGNLVkEugO25cE3TBzSf7Fr7piogO1Psx_a6K-J4mxCdgF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