https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116700
Bug ID: 116700 Summary: `(A > PZ) ? ABS(A) : PZ` -> `MAX(A, PZ)` where PZ is known to be non-negative 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: --- Take: ``` int f(unsigned char a, int b, int c) { int t = a; if (c > t) t = (c > 0 ? c : -c); return t; } int f1(unsigned char a, int b, int c) { int t = a; if (c > t) return (c > 0 ? c : -c); return t; } ``` This should be caught in phiopt1 as being `MAX_EXPR((int)a, c)`. Note for -O2 it is almost caught except VRP does not do copyprop sometimes when it reduces ABS(c) to c. -O1 is not caught at all even though we know that t is non-negative.