https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112310
--- Comment #4 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:2266f7cbc78dfcf7c0739466644e0a6b9966553c commit r14-5095-g2266f7cbc78dfcf7c0739466644e0a6b9966553c Author: Richard Biener <rguent...@suse.de> Date: Fri Nov 3 10:45:18 2023 +0100 tree-optimization/112310 - code hoisting undefined behavior The following avoids hoisting expressions that may invoke undefined behavior and are not computed on all paths. This is realized by noting that we have to avoid materializing expressions as part of hoisting that are not part of the set of expressions we have found eligible for hoisting. Instead of picking the expression corresponding to the hoistable values from the first successor we now keep a union of the expressions so that hoisting can pick the expression that has its dependences fully hoistable. PR tree-optimization/112310 * tree-ssa-pre.cc (do_hoist_insertion): Keep the union of expressions, validate dependences are contained within the hoistable set before hoisting. * gcc.dg/torture/pr112310.c: New testcase.