https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112305
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <rgue...@gcc.gnu.org>: https://gcc.gnu.org/g:e3da1d7bb288c8c864f0284bc4bc5877b466a2f7 commit r14-5032-ge3da1d7bb288c8c864f0284bc4bc5877b466a2f7 Author: Richard Biener <rguent...@suse.de> Date: Tue Oct 31 10:13:13 2023 +0100 tree-optimization/112305 - SCEV cprop and conditional undefined overflow The following adjusts final value replacement to also rewrite the replacement to defined overflow behavior if there's conditionally evaluated stmts (with possibly undefined overflow), not only when we "folded casts". The patch hooks into expression_expensive for this. PR tree-optimization/112305 * tree-scalar-evolution.h (expression_expensive): Adjust. * tree-scalar-evolution.cc (expression_expensive): Record when we see a COND_EXPR. (final_value_replacement_loop): When the replacement contains a COND_EXPR, rewrite it to defined overflow. * tree-ssa-loop-ivopts.cc (may_eliminate_iv): Adjust. * gcc.dg/torture/pr112305.c: New testcase.