https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122608
Bug ID: 122608
Summary: `(a ? CST0 : CST1) OP CST3` is not optimized (for
gimple COND)
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
Target Milestone: ---
Take:
```
__GIMPLE int f(int a)
{
_Bool b;
int t;
b = a > 0;
t = b ? 10 : 20;
t = t + 20;
return t;
}
```
I would have expected this be optimized down to `a > 0 ? 30 : 40` but it is not
currently.
I don't know how much this matters but sometimes VRP (and sccp) creates
COND_EXPR and you might end up with this IR (I don't have a C testcase where
this shows up though).
I noticed this when I saw the LLVM bug
https://github.com/llvm/llvm-project/issues/167014 .
I think clang produces select for ?: agressively rather than how the
gimplification handle it always via ifs.