]> git.ipfire.org Git - thirdparty/gcc.git/commit
match: Fix `a != 0 ? a - 1 : 0` pattern [PR117363]
authorAndrew Pinski <quic_apinski@quicinc.com>
Thu, 31 Oct 2024 04:10:19 +0000 (21:10 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Sun, 3 Nov 2024 18:51:29 +0000 (10:51 -0800)
commit059fdb725ba8210a88a2416a1f819b9ba5453095
treee1e0b8bcc6d1e03e55ebf39f221c9121a764f14e
parent4ed02814c2191d5febe0972c3e43c80c004f4799
match: Fix `a != 0 ? a - 1 : 0` pattern [PR117363]

There are a couple of things wrong with this pattern which
I missed during the review. First each nop_convert should
be nop_convert1 or nop_convert2.
Second is we need to the minus in the same type as the minus
was originally so we don't introduce extra undefined behavior
(signed integer overflow). And we need a convert into the new
type too.

pr117363-1.c tests not introducing extra undefined behavior.
pr117363-2.c tests the casting to the correct final type, ldist
introduces the cond_expr here.

Bootstraped and tested on x86_64-linux-gnu.

PR tree-optimization/117363

gcc/ChangeLog:

* match.pd (`a != 0 ? a - 1 : 0`): Fix type handling
and nop_convert handling.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr117363-1.c: New test.
* gcc.dg/torture/pr117363-2.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr117363-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr117363-2.c [new file with mode: 0644]