diff options
author | Andrew Pinski <apinski@marvell.com> | 2023-08-20 17:22:27 -0700 |
---|---|---|
committer | Andrew Pinski <apinski@marvell.com> | 2023-08-21 00:45:38 -0700 |
commit | 47b833a9abe19d862a773d20dd6f961dcf811a11 (patch) | |
tree | 07092290947f8e29541a2173447697f6494bd7cb /gcc | |
parent | b9426543e8d3b9333d1561844472c3f568fa6913 (diff) | |
download | gcc-47b833a9abe19d862a773d20dd6f961dcf811a11.zip gcc-47b833a9abe19d862a773d20dd6f961dcf811a11.tar.gz gcc-47b833a9abe19d862a773d20dd6f961dcf811a11.tar.bz2 |
MATCH: [PR111002] Sink view_convert for vec_cond
Like convert we can sink view_convert into vec_cond but
we can only do it if the element types are nop_conversions.
This is to allow conversion between signed and unsigned types only.
Rather than between integer and float types which mess up the vec_cond
so that isel does not understand `a?-1:0` is still that.
OK? Bootstrapped and tested on x86_64-linux-gnu and aarch64-linux-gnu.
PR tree-optimization/111002
gcc/ChangeLog:
* match.pd (view_convert(vec_cond(a,b,c))): New pattern.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/sve/cond_convert_8.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/match.pd | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/aarch64/sve/cond_convert_8.c | 22 |
2 files changed, 31 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index d5c731e..86fdc60 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4712,6 +4712,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && types_match (TREE_TYPE (@0), truth_type_for (type))) (vec_cond @0 (convert! @1) (convert! @2)))) +/* Likewise for view_convert of nop_conversions. */ +(simplify + (view_convert (vec_cond:s @0 @1 @2)) + (if (VECTOR_TYPE_P (type) && VECTOR_TYPE_P (TREE_TYPE (@1)) + && known_eq (TYPE_VECTOR_SUBPARTS (type), + TYPE_VECTOR_SUBPARTS (TREE_TYPE (@1))) + && tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@1)))) + (vec_cond @0 (view_convert! @1) (view_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_8.c b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_8.c new file mode 100644 index 0000000..d8b96e5 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_8.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256 -fdump-tree-optimized" } */ +/* PR tree-optimization/111002 */ + +/* We should be able to remove the neg. */ + +void __attribute__ ((noipa)) +f (int *__restrict r, + int *__restrict a, + short *__restrict pred) +{ + for (int i = 0; i < 1024; ++i) + r[i] = pred[i] != 0 ? -1 : 0; +} + + +/* { 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" } } */ |