https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109424
Bug ID: 109424 Summary: ~ Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: pinskia at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` int f(int x, int y) { int t = ((x > y) ? x : y); return ~t; } int f1(int x, int y) { return ~((x > y) ? x : y); } ``` You would assume GCC produce the same code for both, but nope, the first f is worse. The reason why is GCC decides to move the ~ into the ?: operator making the code worse. fold does this "optimization" but nothing undones it, phi-opt undones it for casts in some but not all cases.