https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97784
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- Created attachment 49544 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49544&action=edit patch doing -fwrapv late One piece of the approach would move reassoc after the last VRP pass: diff --git a/gcc/passes.def b/gcc/passes.def index c68231287b6..872511442f1 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -317,7 +317,6 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_lower_vector_ssa); NEXT_PASS (pass_lower_switch); NEXT_PASS (pass_cse_reciprocals); - NEXT_PASS (pass_reassoc, false /* insert_powi_p */); NEXT_PASS (pass_strength_reduction); NEXT_PASS (pass_split_paths); NEXT_PASS (pass_tracer); @@ -332,6 +331,8 @@ along with GCC; see the file COPYING3. If not see /* Threading can leave many const/copy propagations in the IL. Clean them up. */ NEXT_PASS (pass_copy_prop); + NEXT_PASS (pass_reassoc, false /* insert_powi_p */); NEXT_PASS (pass_warn_restrict); NEXT_PASS (pass_dse); NEXT_PASS (pass_cd_dce); that seems to at least regress FAIL: gcc.dg/tree-ssa/pr96480.c scan-tree-dump optimized " = _[0-9]* <= 3;" maybe also some Wstringop-overflow.c diagnostics. Now, altering a flag is a bit awkward since we have to restore it somewhere as 'flag_wrapv' is global state also affecting other functions not yet in late state. A cleaner approach would be to move flag_wrapv (& friends) to struct function fully (and change all users) much like we did for can_throw_non_call_exceptions & flag_non_call_exceptions. Maybe it's not too bad (not so many users of flag_wrapv), but well - have coded the "ugly" variant here. We also can't alter flag_wrapv in case flag_trapv is set, obviously. It might be interesting to do some more pass shuffling here, eventually moving VRP a bit earlier. We're doing a bit much threading and CSE late nowadays. It's also not entirely clear what late passes actually benefit from undefined overflow (besides VRP, that is). Bootstrapped / tested on x86_64-unknown-linux-gnu. FAIL: gcc.dg/pr64434.c scan-rtl-dump-times expand "Swap operands" 1 FAIL: gcc.dg/tree-ssa/phi-opt-15.c scan-tree-dump-not optimized "ABS" FAIL: gcc.dg/tree-ssa/pr44133.c (test for excess errors) FAIL: gcc.dg/tree-ssa/pr92712-3.c scan-tree-dump-not optimized " = [tv]_[0-9]*\\\\(D\\\\) \\\\* [tv]_[0-9]*\\\\(D\\\\);" FAIL: gcc.dg/tree-ssa/pr96480.c scan-tree-dump optimized " = _[0-9]* <= 3;" XPASS: gcc.dg/tree-ssa/reassoc-2.c scan-tree-dump-times optimized "return 0" 1 FAIL: gcc.dg/tree-ssa/slsr-10.c scan-tree-dump-times optimized " \\\\* " 1 FAIL: gcc.dg/tree-ssa/slsr-11.c scan-tree-dump-times optimized " \\\\* " 1 FAIL: gcc.dg/tree-ssa/slsr-13.c scan-tree-dump-times optimized " \\\\* 4" 2 FAIL: gcc.dg/tree-ssa/slsr-20.c scan-tree-dump-times optimized " \\\\* s" 1 FAIL: gcc.dg/tree-ssa/slsr-31.c scan-tree-dump-times optimized " \\\\* 2" 1 FAIL: gcc.dg/tree-ssa/slsr-32.c scan-tree-dump-times optimized " \\\\* 2" 1 FAIL: gcc.dg/tree-ssa/slsr-33.c scan-tree-dump-times optimized " \\\\* " 1 FAIL: gcc.dg/tree-ssa/slsr-34.c scan-tree-dump-times optimized " \\\\* " 1 FAIL: gcc.dg/tree-ssa/slsr-37.c scan-tree-dump-times optimized " \\\\* 2" 1 FAIL: gcc.dg/tree-ssa/slsr-38.c scan-tree-dump-times optimized " \\\\* " 1 FAIL: gcc.dg/tree-ssa/slsr-5.c scan-tree-dump-times optimized " \\\\* " 1 FAIL: gcc.dg/tree-ssa/slsr-7.c scan-tree-dump-times optimized " \\\\* " 1 FAIL: gcc.dg/tree-ssa/slsr-9.c scan-tree-dump-times optimized " \\\\* " 1