Hi! In PR95852 I've added an optimization where next to just pattern recognizing r = x * y; r / x != y or r = x * y; r / x == y as .MUL_OVERFLOW or negation thereof it also recognizes r = x * y; x && (r / x != y) or r = x * y; !x || (r / x == y) by optimizing the guarding condition to always true/false.
The problem with that is that some value ranges recorded for the SSA_NAMEs in the formerly conditional, now unconditional basic block can be invalid. This patch fixes it by calling reset_flow_sensitive_info_in_bb if we optimize the guarding condition. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and after a while to affected release branches? 2025-10-04 Jakub Jelinek <[email protected]> PR tree-optimization/122104 * tree-ssa-math-opts.cc (maybe_optimize_guarding_check): Call reset_flow_sensitive_info_in_bb on bb when optimizing out the guarding condition. * gcc.target/i386/pr122104.c: New test. --- gcc/tree-ssa-math-opts.cc.jj 2025-09-29 15:01:29.865553078 +0200 +++ gcc/tree-ssa-math-opts.cc 2025-10-03 15:09:36.037066116 +0200 @@ -3834,6 +3834,7 @@ maybe_optimize_guarding_check (vec<gimpl else gimple_cond_make_false (zero_cond); update_stmt (zero_cond); + reset_flow_sensitive_info_in_bb (bb); *cfg_changed = true; } --- gcc/testsuite/gcc.target/i386/pr122104.c.jj 2025-10-03 15:51:11.332196041 +0200 +++ gcc/testsuite/gcc.target/i386/pr122104.c 2025-10-03 15:55:39.129458987 +0200 @@ -0,0 +1,12 @@ +/* PR tree-optimization/122104 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-widening_mul-alias" } */ +/* { dg-final { scan-tree-dump "\\.MUL_OVERFLOW" "widening_mul" } } */ +/* { dg-final { scan-tree-dump-not "# RANGE \\\[irange\\\] unsigned int \\\[1, " "widening_mul" } } */ + +int +foo (int x) +{ + int r = (unsigned) x * 35; + return x && ((unsigned) r / x) != 35U; +} Jakub
