https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125793
Bug ID: 125793
Summary: phi_opt should factor out calls
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Depends on: 123113
Blocks: 89018
Target Milestone: ---
Take:
```
long transform(long);
long transform_max(long a, long b, long c) {
if (c)
{
return (a >= b) ? transform(a) : transform(b);
}
return a+b;
}
```
This should be converted into:
```
long transform_max1(long a, long b, long c) {
if (c)
return transform((a >= b) ? a : b);
return a+b;
}
```
This is partly why phiopt needs to do the factoring besides just sink.
Note LLVM does not handle this either because their factoring only happens in a
similar pass to sink where all phi operands need to be happening.
This is what PR 123113 is there to solve.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89018
[Bug 89018] common subexpression present in both branches of condition is not
factored out
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123113
[Bug 123113] factor_out_conditional_operation could be improved to handle
`EDGE_COUNT (merge->preds) != 2`