Simplify "1 - bool_val" to "bool_val ^ 1"
authorAndrew Pinski <apinski@marvell.com>
Tue, 31 Jan 2023 05:03:21 +0000 (05:03 +0000)
committerAndrew Pinski <apinski@marvell.com>
Tue, 14 Feb 2023 21:44:21 +0000 (21:44 +0000)
commita42ed1d9181d21d5cb02f131f641c0cf375eca9d
tree47836e2e44e7b4292edfa155c683981366dcbc98
parent7e300a3d04c18825596ba825c0bbd0cce719ea89
Simplify "1 - bool_val" to "bool_val ^ 1"

For bool values, it is easier to deal with
xor 1 rather than having 1 - a. This is because
we are more likely to simplify the xor further in many
cases.

This is a special case for (MASK - b) where MASK
is a powerof2 - 1 and b <= MASK but only for bool
ranges ([0,1]) as that is the main case where the
difference comes into play.

Note this is enabled for gimple folding only
as the ranges are only know while doing gimple
folding and cfun is not always set when fold is called.

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

gcc/ChangeLog:

PR tree-optimization/108355
PR tree-optimization/96921
* match.pd: Add pattern for "1 - bool_val".

gcc/testsuite/ChangeLog:

PR tree-optimization/108355
PR tree-optimization/96921
* gcc.dg/tree-ssa/bool-minus-1.c: New test.
* gcc.dg/tree-ssa/bool-minus-2.c: New test.
* gcc.dg/tree-ssa/pr108354-1.c: New test.
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/bool-minus-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/bool-minus-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr108354-1.c [new file with mode: 0644]