]> git.ipfire.org Git - thirdparty/gcc.git/commit
match: Fix `a != 0 ? a * b : 0` patterns for things that trap [PR116772]
authorAndrew Pinski <quic_apinski@quicinc.com>
Thu, 19 Sep 2024 20:50:14 +0000 (13:50 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Wed, 25 Sep 2024 15:03:18 +0000 (08:03 -0700)
commit6c5543d3d9c4bbcd19f0ae2b7ed7e523c978a9a8
treeaad71a5a80ec8fec08fc8d7aab6ef44a3657cffd
parent7cf85d137ba8f83a54438f53f557225485c3f695
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_apinski@quicinc.com>
gcc/generic-match-head.cc
gcc/gimple-match-head.cc
gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr116772-1.c [new file with mode: 0644]