MATCH: Sink convert for vec_cond
commit70c50c87273d940918225d5c6b03f1ccfb6f978e
authorAndrew Pinski <apinski@marvell.com>
Tue, 15 Aug 2023 01:35:53 +0000 (14 18:35 -0700)
committerAndrew Pinski <apinski@marvell.com>
Sun, 20 Aug 2023 07:26:19 +0000 (20 00:26 -0700)
treec6f494c33f024dc9eff8f3151e7294d0d98489fc
parent1e3003ca0865329207591896534a6f4fcfde62aa
MATCH: Sink convert for vec_cond

Convert be sinked into a vec_cond if both sides
fold. Unlike other unary operations, we need to check that we still can handle
this vec_cond's first operand is the same as the new truth type.

I tried a few different versions of this patch:
view_convert to the new truth_type but that does not work as we always support all vec_cond
afterwards.
using expand_vec_cond_expr_p; but that would allow too much.

I also tried to see if view_convert can be handled here but we end up with:
  _3 = VEC_COND_EXPR <_2, {  Nan(-1),  Nan(-1),  Nan(-1),  Nan(-1) }, { 0.0, 0.0, 0.0, 0.0 }>;
Which isel does not know how to handle as just being a view_convert from `vector(4) <signed-boolean:32>`
to `vector(4) float` and causes a regression with `g++.target/i386/pr88152.C`

Note, in the case of the SVE testcase, we will sink negate after the convert and be able
to remove a few extra instructions in the end.
Also with this change gcc.target/aarch64/sve/cond_unary_5.c will now pass.

Committed as approved after a bootstrapped and tested on x86_64-linux-gnu and aarch64-linux-gnu.

gcc/ChangeLog:

PR tree-optimization/111006
PR tree-optimization/110986
* match.pd: (op(vec_cond(a,b,c))): Handle convert for op.

gcc/testsuite/ChangeLog:

PR tree-optimization/111006
* gcc.target/aarch64/sve/cond_convert_7.c: New test.
gcc/match.pd
gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c [new file with mode: 0644]