From: Kyrylo Tkachov Date: Mon, 19 Sep 2016 16:15:57 +0000 (+0000) Subject: [simplify-rtx] (GTU (PLUS a C) (C - 1)) --> (LTU a -C) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5fa9e6441ff5169f90d0754b2321d3ddffad89fa;p=gcc.git [simplify-rtx] (GTU (PLUS a C) (C - 1)) --> (LTU a -C) * simplify-rtx.c (simplify_relational_operation_1): Add transformation (GTU (PLUS a C) (C - 1)) --> (LTU a -C). * gcc.target/aarch64/gtu_to_ltu_cmp_1.c: New test. * gcc.target/aarch64/gtu_to_ltu_cmp_2.c: New test. From-SVN: r240238 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 905316d2814..51244467892 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-09-19 Kyrylo Tkachov + + * simplify-rtx.c (simplify_relational_operation_1): Add transformation + (GTU (PLUS a C) (C - 1)) --> (LTU a -C). + 2016-09-19 Segher Boessenkool * target.def (lra_p): Wordsmithing. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 8daef97b473..035f70e89b5 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -4650,6 +4650,19 @@ simplify_relational_operation_1 (enum rtx_code code, machine_mode mode, cmp_mode, XEXP (op0, 0), new_cmp); } + /* (GTU (PLUS a C) (C - 1)) where C is a non-zero constant can be + transformed into (LTU a -C). */ + if (code == GTU && GET_CODE (op0) == PLUS && CONST_INT_P (op1) + && CONST_INT_P (XEXP (op0, 1)) + && (UINTVAL (op1) == UINTVAL (XEXP (op0, 1)) - 1) + && XEXP (op0, 1) != const0_rtx) + { + rtx new_cmp + = simplify_gen_unary (NEG, cmp_mode, XEXP (op0, 1), cmp_mode); + return simplify_gen_relational (LTU, mode, cmp_mode, + XEXP (op0, 0), new_cmp); + } + /* Canonicalize (LTU/GEU (PLUS a b) b) as (LTU/GEU (PLUS a b) a). */ if ((code == LTU || code == GEU) && GET_CODE (op0) == PLUS diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 361ed14ca87..7f2f057fa0d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-19 Kyrylo Tkachov + + * gcc.target/aarch64/gtu_to_ltu_cmp_1.c: New test. + * gcc.target/aarch64/gtu_to_ltu_cmp_2.c: New test. + 2016-09-19 Jakub Jelinek Jan Hubicka diff --git a/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c new file mode 100644 index 00000000000..81c536c90af --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int +f1 (int x, int t) +{ + if (x == -1 || x == -2) + t = 1; + + return t; +} + +/* { dg-final { scan-assembler-times "cmn\\tw\[0-9\]+, #2" 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_2.c b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_2.c new file mode 100644 index 00000000000..e0e999f9df3 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_2.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +unsigned int +foo (unsigned int a, unsigned int b) +{ + return (a + 10) > 9; +} + +/* { dg-final { scan-assembler-times "cmn\\tw\[0-9\]+" 1 } } */ +/* { dg-final { scan-assembler-not "add\\tw\[0-9\]+" } } */