]> git.ipfire.org Git - thirdparty/gcc.git/commit
match: `a CMP nonnegative ? a : ABS<a>` simplified to just `ABS<a>` [PR112392]
authorAndrew Pinski <quic_apinski@quicinc.com>
Tue, 7 May 2024 06:53:41 +0000 (23:53 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Wed, 8 May 2024 15:36:59 +0000 (08:36 -0700)
commit5726de79e2154a16d8a045567d2cfad035f7ed19
tree57e8b06a5307fd2b9c706730fe4e34ecbc930f02
parentf4b86ab09dfe258c4780fcc7567ca8a275c96e7a
match: `a CMP nonnegative ? a : ABS<a>` simplified to just `ABS<a>` [PR112392]

We can optimize `a == nonnegative ? a : ABS<a>`, `a > nonnegative ? a : ABS<a>`
and `a >= nonnegative ? a : ABS<a>` into `ABS<a>`. This allows removal of
some extra comparison and extra conditional moves in some cases.
I don't remember where I had found though but it is simple to add so
let's add it.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Note I have a secondary pattern for the equal case as either a or nonnegative
could be used.

PR tree-optimization/112392

gcc/ChangeLog:

* match.pd (`x CMP nonnegative ? x : ABS<x>`): New pattern;
where CMP is ==, > and >=.
(`x CMP nonnegative@y ? y : ABS<x>`): New pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/phi-opt-41.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-41.c [new file with mode: 0644]