diff options
author | Juergen Christ <jchrist@linux.ibm.com> | 2024-04-01 13:34:37 +0200 |
---|---|---|
committer | Juergen Christ <jchrist@linux.ibm.com> | 2024-04-09 18:06:05 +0200 |
commit | 1f719aa7c0d35b47f3d15a54f074718b78e92bb0 (patch) | |
tree | 1e07e6584ab70066b84fa8b7a2d8ed565e3d3813 /gcc/config/s390 | |
parent | 8075477f81ae8d0abf64b80dfbd179151f91b417 (diff) | |
download | gcc-1f719aa7c0d35b47f3d15a54f074718b78e92bb0.zip gcc-1f719aa7c0d35b47f3d15a54f074718b78e92bb0.tar.gz gcc-1f719aa7c0d35b47f3d15a54f074718b78e92bb0.tar.bz2 |
s390x: Optimize vector permute with constant indexes
Loop vectorizer can generate vector permutes with constant indexes
where all indexes are equal. Optimize this case to use vector
replicate instead of vector permute.
gcc/ChangeLog:
* config/s390/s390.cc (expand_perm_as_replicate): Implement.
(vectorize_vec_perm_const_1): Call new function.
* config/s390/vx-builtins.md (vec_splat<mode>): Change to...
(@vec_splat<mode>): ...this.
gcc/testsuite/ChangeLog:
* gcc.target/s390/vector/vec-expand-replicate.c: New test.
Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
Diffstat (limited to 'gcc/config/s390')
-rw-r--r-- | gcc/config/s390/s390.cc | 33 | ||||
-rw-r--r-- | gcc/config/s390/vx-builtins.md | 2 |
2 files changed, 34 insertions, 1 deletions
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc index 3ee7ae7..bf46eab 100644 --- a/gcc/config/s390/s390.cc +++ b/gcc/config/s390/s390.cc @@ -17933,6 +17933,36 @@ expand_perm_as_a_vlbr_vstbr_candidate (const struct expand_vec_perm_d &d) return false; } +static bool +expand_perm_as_replicate (const struct expand_vec_perm_d &d) +{ + unsigned char i; + unsigned char elem; + rtx base = d.op0; + rtx insn; + /* Needed to silence maybe-uninitialized warning. */ + gcc_assert (d.nelt > 0); + elem = d.perm[0]; + for (i = 1; i < d.nelt; ++i) + if (d.perm[i] != elem) + return false; + if (!d.testing_p) + { + if (elem >= d.nelt) + { + base = d.op1; + elem -= d.nelt; + } + insn = maybe_gen_vec_splat (d.vmode, d.target, base, GEN_INT (elem)); + if (insn == NULL_RTX) + return false; + emit_insn (insn); + return true; + } + else + return maybe_code_for_vec_splat (d.vmode) != CODE_FOR_nothing; +} + /* Try to find the best sequence for the vector permute operation described by D. Return true if the operation could be expanded. */ @@ -17951,6 +17981,9 @@ vectorize_vec_perm_const_1 (const struct expand_vec_perm_d &d) if (expand_perm_as_a_vlbr_vstbr_candidate (d)) return true; + if (expand_perm_as_replicate (d)) + return true; + return false; } diff --git a/gcc/config/s390/vx-builtins.md b/gcc/config/s390/vx-builtins.md index 432d81a..93c0d40 100644 --- a/gcc/config/s390/vx-builtins.md +++ b/gcc/config/s390/vx-builtins.md @@ -424,7 +424,7 @@ ; Replicate from vector element -(define_expand "vec_splat<mode>" +(define_expand "@vec_splat<mode>" [(set (match_operand:V_HW 0 "register_operand" "") (vec_duplicate:V_HW (vec_select:<non_vec> (match_operand:V_HW 1 "register_operand" "") |