From 498b13e24b8a995dd3bb6f0bb734f15b78ef89d1 Mon Sep 17 00:00:00 2001 From: Kyrylo Tkachov Date: Fri, 20 Feb 2015 14:05:51 +0000 Subject: [PATCH] [AArch64] Fix wrong-code bug in right-shift SISD patterns * config/aarch64/aarch64.md (*aarch64_lshr_sisd_or_int_3): Mark operand 0 as earlyclobber in 2nd alternative. (1st define_split below *aarch64_lshr_sisd_or_int_3): Write negated shift amount into QI lowpart operand 0 and use it in the shift step. (2nd define_split below *aarch64_lshr_sisd_or_int_3): Likewise. * gcc.target/aarch64/sisd-shft-neg_1.c: New test. From-SVN: r220860 --- gcc/ChangeLog | 9 +++++ gcc/config/aarch64/aarch64.md | 18 +++++---- gcc/testsuite/ChangeLog | 4 ++ .../gcc.target/aarch64/sisd-shft-neg_1.c | 38 +++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/sisd-shft-neg_1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a899997e8eb..32cc757278b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2015-02-20 Kyrylo Tkachov + + * config/aarch64/aarch64.md (*aarch64_lshr_sisd_or_int_3): + Mark operand 0 as earlyclobber in 2nd alternative. + (1st define_split below *aarch64_lshr_sisd_or_int_3): + Write negated shift amount into QI lowpart operand 0 and use it + in the shift step. + (2nd define_split below *aarch64_lshr_sisd_or_int_3): Likewise. + 2015-02-20 Bernd Schmidt * cgraph.h (clone_function_name_1): Declare. diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 1f4169ee76e..8f157ce2901 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -3360,7 +3360,7 @@ ;; Logical right shift using SISD or Integer instruction (define_insn "*aarch64_lshr_sisd_or_int_3" - [(set (match_operand:GPI 0 "register_operand" "=w,w,r") + [(set (match_operand:GPI 0 "register_operand" "=w,&w,r") (lshiftrt:GPI (match_operand:GPI 1 "register_operand" "w,w,r") (match_operand:QI 2 "aarch64_reg_or_shift_imm_" "Us,w,rUs")))] @@ -3379,11 +3379,13 @@ (match_operand:DI 1 "aarch64_simd_register") (match_operand:QI 2 "aarch64_simd_register")))] "TARGET_SIMD && reload_completed" - [(set (match_dup 2) + [(set (match_dup 3) (unspec:QI [(match_dup 2)] UNSPEC_SISD_NEG)) (set (match_dup 0) - (unspec:DI [(match_dup 1) (match_dup 2)] UNSPEC_SISD_USHL))] - "" + (unspec:DI [(match_dup 1) (match_dup 3)] UNSPEC_SISD_USHL))] + { + operands[3] = gen_lowpart (QImode, operands[0]); + } ) (define_split @@ -3392,11 +3394,13 @@ (match_operand:SI 1 "aarch64_simd_register") (match_operand:QI 2 "aarch64_simd_register")))] "TARGET_SIMD && reload_completed" - [(set (match_dup 2) + [(set (match_dup 3) (unspec:QI [(match_dup 2)] UNSPEC_SISD_NEG)) (set (match_dup 0) - (unspec:SI [(match_dup 1) (match_dup 2)] UNSPEC_USHL_2S))] - "" + (unspec:SI [(match_dup 1) (match_dup 3)] UNSPEC_USHL_2S))] + { + operands[3] = gen_lowpart (QImode, operands[0]); + } ) ;; Arithmetic right shift using SISD or Integer instruction diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2409cfb0fa7..65310fd081d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-02-20 Kyrylo Tkachov + + * gcc.target/aarch64/sisd-shft-neg_1.c: New test. + 2015-02-20 Georg-Johann Lay PR target/64452 diff --git a/gcc/testsuite/gcc.target/aarch64/sisd-shft-neg_1.c b/gcc/testsuite/gcc.target/aarch64/sisd-shft-neg_1.c new file mode 100644 index 00000000000..c091657cb57 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sisd-shft-neg_1.c @@ -0,0 +1,38 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-inline" } */ + +extern void abort (void); + +#define force_simd_si(v) asm volatile ("mov %s0, %1.s[0]" :"=w" (v) :"w" (v) :) + +unsigned int +shft_add (unsigned int a, unsigned int b) +{ + unsigned int c; + + force_simd_si (a); + force_simd_si (b); + c = a >> b; + force_simd_si (c); + + return c + b; +} + +int +main (void) +{ + unsigned int i = 0; + unsigned int a = 0xdeadbeef; + + for (i = 0; i < 32; i++) + { + unsigned int exp = (a / (1 << i) + i); + unsigned int got = shft_add (a, i); + + if (exp != got) + abort (); + } + + return 0; +} + -- 2.30.2