https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116772
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>: https://gcc.gnu.org/g:6c5543d3d9c4bbcd19f0ae2b7ed7e523c978a9a8 commit r15-3870-g6c5543d3d9c4bbcd19f0ae2b7ed7e523c978a9a8 Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Thu Sep 19 13:50:14 2024 -0700 match: Fix `a != 0 ? a * b : 0` patterns for things that trap [PR116772] For generic, `a != 0 ? a * b : 0` would match where `b` would be an expression which trap (in the case of the testcase, it was an integer division but it could be any). This adds a new helper function, expr_no_side_effects_p which tests if there is no side effects and the expression is not trapping which might be used in other locations. Changes since v1: * v2: Add move check to helper function instead of inlining it. PR middle-end/116772 gcc/ChangeLog: * generic-match-head.cc (expr_no_side_effects_p): New function * gimple-match-head.cc (expr_no_side_effects_p): New function * match.pd (`a != 0 ? a / b : 0`): Check expr_no_side_effects_p. (`a != 0 ? a * b : 0`, `a != 0 ? a & b : 0`): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr116772-1.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>