From 69fce32ff9c8ef7bcc4557253798979118d96b43 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Mon, 12 Feb 2007 01:43:50 +0000 Subject: [PATCH] simplify-rtx.c (simplify_relational_operation_1): Optimize comparisons of POPCOUNT against zero. * simplify-rtx.c (simplify_relational_operation_1): Optimize comparisons of POPCOUNT against zero. (simplify_const_relational_operation): Likewise. * gcc.target/ia64/builtin-popcount-1.c: New test case. * gcc.target/ia64/builtin-popcount-2.c: Likewise. From-SVN: r121838 --- gcc/ChangeLog | 6 ++++ gcc/simplify-rtx.c | 29 +++++++++++++++++++ gcc/testsuite/ChangeLog | 5 ++++ .../gcc.target/ia64/builtin-popcount-1.c | 9 ++++++ .../gcc.target/ia64/builtin-popcount-2.c | 9 ++++++ 5 files changed, 58 insertions(+) create mode 100644 gcc/testsuite/gcc.target/ia64/builtin-popcount-1.c create mode 100644 gcc/testsuite/gcc.target/ia64/builtin-popcount-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 73feadee38b..a5f9960a1ae 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2007-02-11 Roger Sayle + + * simplify-rtx.c (simplify_relational_operation_1): Optimize + comparisons of POPCOUNT against zero. + (simplify_const_relational_operation): Likewise. + 2007-02-11 Manuel Lopez-Ibanez * doc/invoke.texi (Wextra): Delete outdated paragraph. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 8d8bbe52d0c..6f7c37d4c56 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -3802,6 +3802,27 @@ simplify_relational_operation_1 (enum rtx_code code, enum machine_mode mode, simplify_gen_binary (XOR, cmp_mode, XEXP (op0, 1), op1)); + if (op0code == POPCOUNT && op1 == const0_rtx) + switch (code) + { + case EQ: + case LE: + case LEU: + /* (eq (popcount x) (const_int 0)) -> (eq x (const_int 0)). */ + return simplify_gen_relational (EQ, mode, GET_MODE (XEXP (op0, 0)), + XEXP (op0, 0), const0_rtx); + + case NE: + case GT: + case GTU: + /* (ne (popcount x) (const_int 0)) -> (ne x (const_int 0)). */ + return simplify_gen_relational (EQ, mode, GET_MODE (XEXP (op0, 0)), + XEXP (op0, 0), const0_rtx); + + default: + break; + } + return NULL_RTX; } @@ -4067,6 +4088,10 @@ simplify_const_relational_operation (enum rtx_code code, if (GET_CODE (tem) == ABS) return const0_rtx; } + + /* Optimize popcount (x) < 0. */ + if (GET_CODE (trueop0) == POPCOUNT && trueop1 == const0_rtx) + return const_true_rtx; break; case GE: @@ -4081,6 +4106,10 @@ simplify_const_relational_operation (enum rtx_code code, if (GET_CODE (tem) == ABS) return const_true_rtx; } + + /* Optimize popcount (x) >= 0. */ + if (GET_CODE (trueop0) == POPCOUNT && trueop1 == const0_rtx) + return const_true_rtx; break; case UNGE: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b6a6c0a8832..92670f42758 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-02-11 Roger Sayle + + * gcc.target/ia64/builtin-popcount-1.c: New test case. + * gcc.target/ia64/builtin-popcount-2.c: Likewise. + 2007-02-11 Tobias Schlüter PR fortran/30478 diff --git a/gcc/testsuite/gcc.target/ia64/builtin-popcount-1.c b/gcc/testsuite/gcc.target/ia64/builtin-popcount-1.c new file mode 100644 index 00000000000..c9641d0e6df --- /dev/null +++ b/gcc/testsuite/gcc.target/ia64/builtin-popcount-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler "popcnt" } } */ + +int foo (int x) +{ + return __builtin_popcount (x); +} + diff --git a/gcc/testsuite/gcc.target/ia64/builtin-popcount-2.c b/gcc/testsuite/gcc.target/ia64/builtin-popcount-2.c new file mode 100644 index 00000000000..50ced72e728 --- /dev/null +++ b/gcc/testsuite/gcc.target/ia64/builtin-popcount-2.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "popcnt" } } */ + +int foo (int x) +{ + return __builtin_popcount (x) == 0; +} + -- 2.30.2