aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-08-14 18:35:53 -0700
committerAndrew Pinski <apinski@marvell.com>2023-08-20 00:26:19 -0700
commit70c50c87273d940918225d5c6b03f1ccfb6f978e (patch)
treec6f494c33f024dc9eff8f3151e7294d0d98489fc /gcc
parent1e3003ca0865329207591896534a6f4fcfde62aa (diff)
downloadgcc-70c50c87273d940918225d5c6b03f1ccfb6f978e.zip
gcc-70c50c87273d940918225d5c6b03f1ccfb6f978e.tar.gz
gcc-70c50c87273d940918225d5c6b03f1ccfb6f978e.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/match.pd8
-rw-r--r--gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c23
2 files changed, 31 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index acd2a96..d5c731e 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4704,6 +4704,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(op (vec_cond:s @0 @1 @2))
(vec_cond @0 (op! @1) (op! @2))))
+/* Sink unary conversions to branches, but only if we do fold both
+ and the target's truth type is the same as we already have. */
+(simplify
+ (convert (vec_cond:s @0 @1 @2))
+ (if (VECTOR_TYPE_P (type)
+ && types_match (TREE_TYPE (@0), truth_type_for (type)))
+ (vec_cond @0 (convert! @1) (convert! @2))))
+
/* Sink binary operation to branches, but only if we can fold it. */
(for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor
lshift rshift rdiv trunc_div ceil_div floor_div round_div
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c
new file mode 100644
index 0000000..4bb95b9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256 -fdump-tree-optimized" } */
+
+/* This is a modified reduced version of cond_unary_5.c */
+
+void __attribute__ ((noipa))
+f0 (unsigned short *__restrict r,
+ int *__restrict a,
+ int *__restrict pred)
+{
+ for (int i = 0; i < 1024; ++i)
+ {
+ int p = pred[i]?-1:0;
+ r[i] = p ;
+ }
+}
+
+/* { dg-final { scan-assembler-times {\tmov\tz[0-9]+\.h, p[0-7]+/z, #-1} 1 } } */
+/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.[hs], p[0-7]+/z, #1} } } */
+
+/* { dg-final { scan-tree-dump-not "VIEW_CONVERT_EXPR " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " = -" "optimized" } } */
+/* { dg-final { scan-tree-dump-not " = \\\(vector" "optimized" } } */