]> git.ipfire.org Git - thirdparty/gcc.git/commit
vect: Fix voluntarily-masked negative conditionals [PR108430]
authorRichard Sandiford <richard.sandiford@arm.com>
Mon, 3 Apr 2023 08:57:06 +0000 (09:57 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Mon, 3 Apr 2023 08:57:06 +0000 (09:57 +0100)
commit33a69d0b0b772610463d1d586f3f0c9820fc969e
treed49243bcd70e13af80b6b57c98e0253a2623c869
parent160c5f354a6dc8a660ff8ad8574279b0d3fb412d
vect: Fix voluntarily-masked negative conditionals [PR108430]

vectorizable_condition checks whether a COND_EXPR condition is used
elsewhere with a loop mask.  If so, it applies the loop mask to the
COND_EXPR too, to reduce the number of live masks and to increase the
chance of combining the AND with the comparison.

There is also code to do this for inverted conditions.  E.g. if
we have a < b ? c : d and something else is conditional on !(a < b)
(such as a load in d), we use !(a < b) ? d : c and apply the loop
mask to !(a < b).

This inversion relied on the function's bitop1/bitop2 mechanism.
However, that mechanism is skipped if the condition is split out of
the COND_EXPR as a separate statement.  This meant that we could end
up using the inverse of the intended condition.

There is a separate way of negating the condition when a mask
is being applied (which is also used for EXTRACT_LAST reductions).
This patch uses that instead.

As well as the testcase, this fixes aarch64/sve/vcond_{4,17}_run.c.

gcc/
PR tree-optimization/108430
* tree-vect-stmts.cc (vectorizable_condition): Fix handling
of inverted condition.

gcc/testsuite/
PR tree-optimization/108430
* gcc.target/aarch64/sve/pr108430.c: New test.

(cherry picked from commit 2a8ce4b52f5892a10a02b94d7be689e59a444ff6)
gcc/testsuite/gcc.target/aarch64/sve/pr108430.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc