https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115999
Bug ID: 115999 Summary: a - (a>>31) should be transformed into a + ((unsigned)a)>>31 (for signed a) Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` int f0(int a) { return a - (a >> (sizeof(a)*8 - 1)); } int f(int a) { int t = a >> (sizeof(a)*8 - 1); return a - t; } int f1(int a) { unsigned t = ((unsigned)a) >> (sizeof(a)*8 - 1); return a + t; } int feq(int a) { return f(a) == f1(a); } ``` f0, f and f1 all should produce the same code generation but currently does not. feq shows that we can't figure out that f and f1 are the same even though they are. I saw this when reading https://gcc.gnu.org/pipermail/gcc-patches/2024-July/657751.html .