From 274b2532360e1615cdbde890c32c928c69ac45cc Mon Sep 17 00:00:00 2001 From: Kyrylo Tkachov Date: Mon, 9 Sep 2013 13:32:50 +0000 Subject: [PATCH] aarch64.c (aarch64_select_cc_mode): Return CC_SWP for comparison with negated operand. [gcc/] 2013-09-09 Kyrylo Tkachov * config/aarch64/aarch64.c (aarch64_select_cc_mode): Return CC_SWP for comparison with negated operand. * config/aarch64/aarch64.md (compare_neg): Match canonical RTL form. [gcc/testsuite/] 2013-09-09 Kyrylo Tkachov * gcc.target/aarch64/cmn-neg.c: New test. From-SVN: r202400 --- gcc/ChangeLog | 6 ++++ gcc/config/aarch64/aarch64.c | 5 ++-- gcc/config/aarch64/aarch64.md | 10 +++---- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.target/aarch64/cmn-neg.c | 33 ++++++++++++++++++++++ 5 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/cmn-neg.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 228fd1bad57..9a94ff4b861 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2013-09-09 Kyrylo Tkachov + + * config/aarch64/aarch64.c (aarch64_select_cc_mode): Return CC_SWP for + comparison with negated operand. + * config/aarch64/aarch64.md (compare_neg): Match canonical RTL form. + 2013-09-09 Richard Biener PR middle-end/58326 diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 7635e1e2679..d0bd38eaef0 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -3313,14 +3313,15 @@ aarch64_select_cc_mode (RTX_CODE code, rtx x, rtx y) || GET_CODE (x) == NEG)) return CC_NZmode; - /* A compare with a shifted operand. Because of canonicalization, + /* A compare with a shifted or negated operand. Because of canonicalization, the comparison will have to be swapped when we emit the assembly code. */ if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode) && (GET_CODE (y) == REG || GET_CODE (y) == SUBREG) && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT || GET_CODE (x) == LSHIFTRT - || GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)) + || GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND + || GET_CODE (x) == NEG)) return CC_SWPmode; /* A compare of a mode narrower than SI mode against zero can be done diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index f37f98f9994..0cd7da7a399 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -1480,12 +1480,12 @@ ) (define_insn "*compare_neg" - [(set (reg:CC CC_REGNUM) - (compare:CC - (match_operand:GPI 0 "register_operand" "r") - (neg:GPI (match_operand:GPI 1 "register_operand" "r"))))] + [(set (reg:CC_SWP CC_REGNUM) + (compare:CC_SWP + (neg:GPI (match_operand:GPI 0 "register_operand" "r")) + (match_operand:GPI 1 "register_operand" "r")))] "" - "cmn\\t%0, %1" + "cmn\\t%1, %0" [(set_attr "v8type" "alus") (set_attr "type" "alus_reg") (set_attr "mode" "")] diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3bb49d9bb77..ffe4acb1985 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-09-09 Kyrylo Tkachov + + * gcc.target/aarch64/cmn-neg.c: New test. + 2013-09-09 Richard Biener PR middle-end/58326 diff --git a/gcc/testsuite/gcc.target/aarch64/cmn-neg.c b/gcc/testsuite/gcc.target/aarch64/cmn-neg.c new file mode 100644 index 00000000000..05c8bbff5be --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/cmn-neg.c @@ -0,0 +1,33 @@ +/* { dg-do run } */ +/* { dg-options "-O2 --save-temps" } */ + +extern void abort (void); + +void __attribute__ ((noinline)) +foo_s32 (int a, int b) +{ + if (a < -b) + abort (); +} +/* { dg-final { scan-assembler "cmn\tw\[0-9\]" } } */ + +void __attribute__ ((noinline)) +foo_s64 (long long a, long long b) +{ + if (a < -b) + abort (); +} +/* { dg-final { scan-assembler "cmn\tx\[0-9\]" } } */ + + +int +main (void) +{ + int a = 30; + int b = 42; + foo_s32 (a, b); + foo_s64 (a, b); + return 0; +} + +/* { dg-final { cleanup-saved-temps } } */