https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123113
Bug ID: 123113
Summary: factor_out_conditional_operation could be improved to
handle `EDGE_COUNT (merge->preds) != 2`
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
While thinking about the recent removal of forwarder blocks, I found that
factor_out_conditional_operation does not handle `EDGE_COUNT (merge->preds) !=
2` as it does not insert a new block. I think we should be able to do it.
Take:
```
int f(int a, int b, int c, int d)
{
if (a)
{
if (b){
c = c > d ? c : d;
c = -c;
}
else {
c = c > d ? c : d;
c = -c;
}
}
return c;
}
```
This should be optimized at -O1 but currently we don't. -O2 works because of
PRE/code hoisting.
Note this is not a regression but I am filing this for future work for GCC 17.
Since merge_phi has been in the pipeline before phiopt; this is not a
regression which was exposed by the remove forwarders patch either.