From 06b1198f7584b1e1cec68f96b9525629d6beeab0 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Mon, 12 Nov 2012 19:39:46 +0000 Subject: [PATCH] Use CSINC instead of CSEL to return 1 (AArch64) From-SVN: r193452 --- gcc/ChangeLog | 8 ++++++++ gcc/config/aarch64/aarch64.md | 16 ++++++++++------ gcc/config/aarch64/constraints.md | 5 +++++ gcc/config/aarch64/predicates.md | 5 +++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.target/aarch64/csinc-2.c | 14 ++++++++++++++ 6 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/csinc-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c03a235..ac11617 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,13 @@ 2012-11-12 Ian Bolton + * config/aarch64/aarch64.md (cmov_insn): Emit CSINC when + one of the alternatives is constant 1. + * config/aarch64/constraints.md: New constraint. + * config/aarch64/predicates.md: Rename predicate + aarch64_reg_zero_or_m1 to aarch64_reg_zero_or_m1_or_1. + +2012-11-12 Ian Bolton + * config/aarch64/aarch64.md (*compare_neg): New pattern. 2012-11-12 Tobias Burnus diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 077a89e..a9a8b5f 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -1885,19 +1885,23 @@ ) (define_insn "*cmov_insn" - [(set (match_operand:ALLI 0 "register_operand" "=r,r,r,r") + [(set (match_operand:ALLI 0 "register_operand" "=r,r,r,r,r,r,r") (if_then_else:ALLI (match_operator 1 "aarch64_comparison_operator" [(match_operand 2 "cc_register" "") (const_int 0)]) - (match_operand:ALLI 3 "aarch64_reg_zero_or_m1" "rZ,rZ,UsM,UsM") - (match_operand:ALLI 4 "aarch64_reg_zero_or_m1" "rZ,UsM,rZ,UsM")))] - "" - ;; Final alternative should be unreachable, but included for completeness + (match_operand:ALLI 3 "aarch64_reg_zero_or_m1_or_1" "rZ,rZ,UsM,rZ,Ui1,UsM,Ui1") + (match_operand:ALLI 4 "aarch64_reg_zero_or_m1_or_1" "rZ,UsM,rZ,Ui1,rZ,UsM,Ui1")))] + "!((operands[3] == const1_rtx && operands[4] == constm1_rtx) + || (operands[3] == constm1_rtx && operands[4] == const1_rtx))" + ;; Final two alternatives should be unreachable, but included for completeness "@ csel\\t%0, %3, %4, %m1 csinv\\t%0, %3, zr, %m1 csinv\\t%0, %4, zr, %M1 - mov\\t%0, -1" + csinc\\t%0, %3, zr, %m1 + csinc\\t%0, %4, zr, %M1 + mov\\t%0, -1 + mov\\t%0, 1" [(set_attr "v8type" "csel") (set_attr "mode" "")] ) diff --git a/gcc/config/aarch64/constraints.md b/gcc/config/aarch64/constraints.md index fe61307..dae4b94 100644 --- a/gcc/config/aarch64/constraints.md +++ b/gcc/config/aarch64/constraints.md @@ -102,6 +102,11 @@ A constraint that matches the immediate constant -1." (match_test "op == constm1_rtx")) +(define_constraint "Ui1" + "@internal + A constraint that matches the immediate constant +1." + (match_test "op == const1_rtx")) + (define_constraint "Ui3" "@internal A constraint that matches the integers 0...4." diff --git a/gcc/config/aarch64/predicates.md b/gcc/config/aarch64/predicates.md index 6f79039..80f6ce2 100644 --- a/gcc/config/aarch64/predicates.md +++ b/gcc/config/aarch64/predicates.md @@ -31,11 +31,12 @@ (ior (match_operand 0 "register_operand") (match_test "op == const0_rtx")))) -(define_predicate "aarch64_reg_zero_or_m1" +(define_predicate "aarch64_reg_zero_or_m1_or_1" (and (match_code "reg,subreg,const_int") (ior (match_operand 0 "register_operand") (ior (match_test "op == const0_rtx") - (match_test "op == constm1_rtx"))))) + (ior (match_test "op == constm1_rtx") + (match_test "op == const1_rtx")))))) (define_predicate "aarch64_fp_compare_operand" (ior (match_operand 0 "register_operand") diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3cda5b6..9c93370 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2012-11-12 Ian Bolton + * gcc.target/aarch64/csinc-2.c: New test. + +2012-11-12 Ian Bolton + * gcc.target/aarch64/cmn.c: New test. * gcc.target/aarch64/adds.c: New test. * gcc.target/aarch64/subs.c: New test. diff --git a/gcc/testsuite/gcc.target/aarch64/csinc-2.c b/gcc/testsuite/gcc.target/aarch64/csinc-2.c new file mode 100644 index 0000000..1b4eb7e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/csinc-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int +foo (int a, int b) +{ + return (a < b) ? 1 : 7; + /* { dg-final { scan-assembler "csinc\tw\[0-9\].*wzr" } } */ +} + +typedef long long s64; + +s64 +foo2 (s64 a, s64 b) -- 2.7.4