https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116702
Bug ID: 116702 Summary: `MIN_EXPR <MAX_EXPR<a, -1> , 0>` can be optimized to `a >> (BITSIZE-1)` for signed types Product: gcc Version: 15.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: --- While looking into something phiopt related I accidently noticed that: ``` int f(int a, int b, int c) { int t = (c > -1 ? c : -1); int t2 = (t < 0) ? t : 0; return t2; } int f2(int a, int b, int c) { int t = (c > -1 ? c : -1); if (c < 0) return t; return 0; } ``` these 2 could be optimized to just: `return a >> (BITSIZE-1);` At -O2, we are able to optimize f2 to that. But at -O1 we fail both.