From: Kyrylo Tkachov <[email protected]>

The VEC_CONCAT simplification added for PR target/48609 in b085ae4b49b4
rewrites

  (vec_concat:N (subreg:N/2 OP 0) (subreg:N/2 OP N/2))

into a lowpart of OP without checking that the target allows accessing
OP in the result mode.  On AArch64, V2x8QI (two D registers) and V16QI
(one Q register) have the same size but cannot be tied.  The vtbl2 and
vtbx2 expanders build the table with aarch64_combinev8qi from the two
halves of a V2x8QI tuple, so combine now produces

  (set (reg:V16QI table) (subreg:V16QI (reg:V2x8QI tuple) 0))

which reload can only satisfy through the stack:

  sub   sp, sp, #16
  stp   d0, d1, [sp]
  ldr   q31, [sp]
  tbl   v0.8b, {v31.16b}, v2.8b
  add   sp, sp, 16
  ret

Require targetm.modes_tieable_p for register bases, so the VEC_CONCAT is
kept and the code is:

  zip1  v0.2d, v0.2d, v1.2d
  tbl   v0.8b, {v0.16b}, v2.8b
  ret

The vtbl2 and vtbx2 tests in gcc.target/aarch64/neon expected the stack
sequence, so update them to the new code.  This also fixes the test_tbl2
and test_tbx2 failures in gcc.target/aarch64/simd/mf8_data_1.c.

Bootstrapped and tested on aarch64-none-linux-gnu.
Ok for trunk?
Thanks,
Kyrill

gcc/ChangeLog:

        * simplify-rtx.cc (simplify_context::simplify_binary_operation_1)
        <case VEC_CONCAT>: Check targetm.modes_tieable_p before merging
        subregs of the same register.

gcc/testsuite/ChangeLog:

        * gcc.target/aarch64/neon/vtbl.c: Expect zip1 instead of a stack
        round trip for vtbl2.
        * gcc.target/aarch64/neon/vtbx.c: Likewise for vtbx2.

Signed-off-by: Kyrylo Tkachov <[email protected]>
---
 gcc/simplify-rtx.cc                          |  4 +++-
 gcc/testsuite/gcc.target/aarch64/neon/vtbl.c | 20 ++++----------------
 gcc/testsuite/gcc.target/aarch64/neon/vtbx.c | 20 ++++----------------
 3 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 53c8da5c156..f7da362c47e 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -5769,7 +5769,7 @@ simplify_ashift:
             (subreg:N/2 OP 0)
             (subreg:N/2 OP N/2)) --> OP
           i.e. where concatenating the first and second halves of the
-          same object OP.  */
+          same object OP, if the target allows accessing OP in MODE.  */
        {
          poly_uint64 offset = 0u;
          rtx base0 = get_ref_base_and_offset (trueop0, &offset);
@@ -5780,6 +5780,8 @@ simplify_ashift:
              rtx base1 = get_ref_base_and_offset (trueop1, &offset);
              if (rtx_equal_p (base0, base1)
                  && known_eq (offset, GET_MODE_SIZE (op0_mode))
+                 && (!REG_P (base0)
+                     || targetm.modes_tieable_p (GET_MODE (base0), mode))
                  && !side_effects_p (trueop0)
                  && !side_effects_p (trueop1))
                {
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/vtbl.c 
b/gcc/testsuite/gcc.target/aarch64/neon/vtbl.c
index cece43af692..746f2cad0b7 100644
--- a/gcc/testsuite/gcc.target/aarch64/neon/vtbl.c
+++ b/gcc/testsuite/gcc.target/aarch64/neon/vtbl.c
@@ -37,10 +37,7 @@ TEST_BINARY (vtbl1_mf8, mfloat8x8_t, mfloat8x8_t, uint8x8_t)
 
 /*
 ** test_vtbl2_s8:
-**     sub     sp, sp, #16
-**     stp     d[0-9]+, d[0-9]+, \[sp\]
-**     ldr     q[0-9]+, \[sp\]
-**     add     sp, sp, 16
+**     zip1    v[0-9]+\.2d, v[0-9]+\.2d, v[0-9]+\.2d
 **     tbl     v[0-9]+\.8b, {v[0-9]+\.16b}, v[0-9]+\.8b
 **     ret
 */
@@ -48,10 +45,7 @@ TEST_BINARY (vtbl2_s8, int8x8_t, int8x8x2_t, int8x8_t)
 
 /*
 ** test_vtbl2_u8:
-**     sub     sp, sp, #16
-**     stp     d[0-9]+, d[0-9]+, \[sp\]
-**     ldr     q[0-9]+, \[sp\]
-**     add     sp, sp, 16
+**     zip1    v[0-9]+\.2d, v[0-9]+\.2d, v[0-9]+\.2d
 **     tbl     v[0-9]+\.8b, {v[0-9]+\.16b}, v[0-9]+\.8b
 **     ret
 */
@@ -59,10 +53,7 @@ TEST_BINARY (vtbl2_u8, uint8x8_t, uint8x8x2_t, uint8x8_t)
 
 /*
 ** test_vtbl2_p8:
-**     sub     sp, sp, #16
-**     stp     d[0-9]+, d[0-9]+, \[sp\]
-**     ldr     q[0-9]+, \[sp\]
-**     add     sp, sp, 16
+**     zip1    v[0-9]+\.2d, v[0-9]+\.2d, v[0-9]+\.2d
 **     tbl     v[0-9]+\.8b, {v[0-9]+\.16b}, v[0-9]+\.8b
 **     ret
 */
@@ -70,10 +61,7 @@ TEST_BINARY (vtbl2_p8, poly8x8_t, poly8x8x2_t, uint8x8_t)
 
 /*
 ** test_vtbl2_mf8:
-**     sub     sp, sp, #16
-**     stp     d[0-9]+, d[0-9]+, \[sp\]
-**     ldr     q[0-9]+, \[sp\]
-**     add     sp, sp, 16
+**     zip1    v[0-9]+\.2d, v[0-9]+\.2d, v[0-9]+\.2d
 **     tbl     v[0-9]+\.8b, {v[0-9]+\.16b}, v[0-9]+\.8b
 **     ret
 */
diff --git a/gcc/testsuite/gcc.target/aarch64/neon/vtbx.c 
b/gcc/testsuite/gcc.target/aarch64/neon/vtbx.c
index 3bdf7817023..cfa938d71e3 100644
--- a/gcc/testsuite/gcc.target/aarch64/neon/vtbx.c
+++ b/gcc/testsuite/gcc.target/aarch64/neon/vtbx.c
@@ -50,10 +50,7 @@ TEST_TERNARY (vtbx1_mf8, mfloat8x8_t, mfloat8x8_t, 
mfloat8x8_t, uint8x8_t)
 
 /*
 ** test_vtbx2_s8:
-**     sub     sp, sp, #16
-**     stp     d[0-9]+, d[0-9]+, \[sp\]
-**     ldr     q[0-9]+, \[sp\]
-**     add     sp, sp, 16
+**     zip1    v[0-9]+\.2d, v[0-9]+\.2d, v[0-9]+\.2d
 **     tbx     v[0-9]+\.8b, {v[0-9]+\.16b}, v[0-9]+\.8b
 **     ret
 */
@@ -61,10 +58,7 @@ TEST_TERNARY (vtbx2_s8, int8x8_t, int8x8_t, int8x8x2_t, 
int8x8_t)
 
 /*
 ** test_vtbx2_u8:
-**     sub     sp, sp, #16
-**     stp     d[0-9]+, d[0-9]+, \[sp\]
-**     ldr     q[0-9]+, \[sp\]
-**     add     sp, sp, 16
+**     zip1    v[0-9]+\.2d, v[0-9]+\.2d, v[0-9]+\.2d
 **     tbx     v[0-9]+\.8b, {v[0-9]+\.16b}, v[0-9]+\.8b
 **     ret
 */
@@ -72,10 +66,7 @@ TEST_TERNARY (vtbx2_u8, uint8x8_t, uint8x8_t, uint8x8x2_t, 
uint8x8_t)
 
 /*
 ** test_vtbx2_p8:
-**     sub     sp, sp, #16
-**     stp     d[0-9]+, d[0-9]+, \[sp\]
-**     ldr     q[0-9]+, \[sp\]
-**     add     sp, sp, 16
+**     zip1    v[0-9]+\.2d, v[0-9]+\.2d, v[0-9]+\.2d
 **     tbx     v[0-9]+\.8b, {v[0-9]+\.16b}, v[0-9]+\.8b
 **     ret
 */
@@ -83,10 +74,7 @@ TEST_TERNARY (vtbx2_p8, poly8x8_t, poly8x8_t, poly8x8x2_t, 
uint8x8_t)
 
 /*
 ** test_vtbx2_mf8:
-**     sub     sp, sp, #16
-**     stp     d[0-9]+, d[0-9]+, \[sp\]
-**     ldr     q[0-9]+, \[sp\]
-**     add     sp, sp, 16
+**     zip1    v[0-9]+\.2d, v[0-9]+\.2d, v[0-9]+\.2d
 **     tbx     v[0-9]+\.8b, {v[0-9]+\.16b}, v[0-9]+\.8b
 **     ret
 */
-- 
2.54.0 (Apple Git-157)

Reply via email to