https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113383
Bug ID: 113383 Summary: `MAX(a,b) == 0` and `MAX(a,b) != 0` can be simplified (for unsigned types) Product: gcc Version: 14.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: ``` unsigned maxeq0(unsigned a, unsigned b) { unsigned c = a > b ? a : b; return c == 0; // b == 0 && a == 0 } unsigned maxeq0_1(unsigned a, unsigned b) { return b == 0 && a == 0; } unsigned maxne0(unsigned a, unsigned b) { unsigned c = a > b ? a : b; return c != 0; // b != 0 || a != 0 } unsigned maxne0_1(unsigned a, unsigned b) { return b != 0 || a != 0; } ``` maxeq0 and maxeq0_1 are equivalent. Likewise for maxne0 and maxne0_1. LLVM is able to do this simplification. Note this is only valid for unsigned MAX.