[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 --- Comment #12 from CVS Commits --- The releases/gcc-12 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:9e72a522dd9f835dd159fe3aff493eee001be0d4 commit r12-8523-g9e72a522dd9f835dd159fe3aff493eee001be0d4 Author: Jakub Jelinek Date: Tue Jun 21 11:40:16 2022 +0200 ifcvt: Don't introduce trapping or faulting reads in noce_try_sign_mask [PR106032] noce_try_sign_mask as documented will optimize if (c < 0) x = t; else x = 0; into x = (c >> bitsm1) & t; The optimization is done if either t is unconditional (e.g. for x = t; if (c >= 0) x = 0; ) or if it is cheap. We already check that t doesn't have side-effects, but if t is conditional, we need to punt also if it may trap or fault, as we make it unconditional. I've briefly skimmed other noce_try* optimizations and didn't find one that would suffer from the same problem. 2022-06-21 Jakub Jelinek PR rtl-optimization/106032 * ifcvt.cc (noce_try_sign_mask): Punt if !t_unconditional, and t may_trap_or_fault_p, even if it is cheap. * gcc.c-torture/execute/pr106032.c: New test. (cherry picked from commit a0c30fe3b888f20215f3e040d21b62b603804ca9)
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 Jakub Jelinek changed: What|Removed |Added Target Milestone|10.4|10.5 --- Comment #11 from Jakub Jelinek --- GCC 10.4 is being released, retargeting bugs to GCC 10.5.
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 --- Comment #10 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:a0c30fe3b888f20215f3e040d21b62b603804ca9 commit r13-1186-ga0c30fe3b888f20215f3e040d21b62b603804ca9 Author: Jakub Jelinek Date: Tue Jun 21 11:40:16 2022 +0200 ifcvt: Don't introduce trapping or faulting reads in noce_try_sign_mask [PR106032] noce_try_sign_mask as documented will optimize if (c < 0) x = t; else x = 0; into x = (c >> bitsm1) & t; The optimization is done if either t is unconditional (e.g. for x = t; if (c >= 0) x = 0; ) or if it is cheap. We already check that t doesn't have side-effects, but if t is conditional, we need to punt also if it may trap or fault, as we make it unconditional. I've briefly skimmed other noce_try* optimizations and didn't find one that would suffer from the same problem. 2022-06-21 Jakub Jelinek PR rtl-optimization/106032 * ifcvt.cc (noce_try_sign_mask): Punt if !t_unconditional, and t may_trap_or_fault_p, even if it is cheap. * gcc.c-torture/execute/pr106032.c: New test.
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 Jakub Jelinek changed: What|Removed |Added Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org Status|NEW |ASSIGNED --- Comment #9 from Jakub Jelinek --- Created attachment 53170 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53170=edit gcc13-pr106032.patch Untested fix.
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #8 from Jakub Jelinek --- Started likely with r0-57085
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 --- Comment #7 from Jakub Jelinek --- This one seems to be very old: __attribute__((noipa, noinline, noclone)) int foo (int x, int *y) { int a = 0; if (x < 0) a = *y; return a; } int main () { int a = 42; if (foo (0, 0) != 0 || foo (1, 0) != 0) __builtin_abort (); if (foo (-1, ) != 42 || foo (-42, ) != 42) __builtin_abort (); return 0; } I guess checking may_trap_p or may_trap_or_fault_p in noce_try_sign_mask would fix this, but we probably should check other noce_* functions how they handle possibly faulting memory.
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 Richard Biener changed: What|Removed |Added Priority|P3 |P2
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 --- Comment #6 from Andrew Pinski --- (In reply to Martin Liška from comment #5) > (In reply to Andrew Pinski from comment #4) > > Here is a testcase which shows this was latent but fails in GCC 7+ (so it is > > still a regression): > > int a, b, c, *d; > > int main() { > > int e = 0, f = 0; > > int *dd = d; > > for (; f < 1; f++) > > if (c < 0) > > e = *dd; > > if (a) { > > a = b ? 0 : a; > > e && (b = a); > > } > > return 0; > > } > > This one started with r9-6299-gd7a700e0a701e516. I guess I need to make another testcase since that would have just changed the gimple level.
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 Martin Liška changed: What|Removed |Added CC||marxin at gcc dot gnu.org, ||rguenth at gcc dot gnu.org --- Comment #5 from Martin Liška --- (In reply to Andrew Pinski from comment #4) > Here is a testcase which shows this was latent but fails in GCC 7+ (so it is > still a regression): > int a, b, c, *d; > int main() { > int e = 0, f = 0; > int *dd = d; > for (; f < 1; f++) > if (c < 0) > e = *dd; > if (a) { > a = b ? 0 : a; > e && (b = a); > } > return 0; > } This one started with r9-6299-gd7a700e0a701e516.
[Bug rtl-optimization/106032] [10/11/12/13 Regression] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106032 Andrew Pinski changed: What|Removed |Added Summary|[12/13 Regression] wrong|[10/11/12/13 Regression] |code at -Os and above on|wrong code at -Os and above |x86_64-linux-gnu|on x86_64-linux-gnu Known to work|11.3.0 |6.1.0, 6.4.0 Target Milestone|13.0|10.4 Known to fail||7.1.0, 8.1.0, 9.1.0 --- Comment #4 from Andrew Pinski --- Here is a testcase which shows this was latent but fails in GCC 7+ (so it is still a regression): int a, b, c, *d; int main() { int e = 0, f = 0; int *dd = d; for (; f < 1; f++) if (c < 0) e = *dd; if (a) { a = b ? 0 : a; e && (b = a); } return 0; }