summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2006-05-30 15:32:52 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2006-05-30 15:32:52 +0000
commit445e5fbbc093303ce94e4f8031853af2a2d2fd68 (patch)
tree6d1370f585fb59eba673c1d1c7a7b0721cf849ac
parent72370f24b054986ae91deabd43fc9ae80115aa65 (diff)
downloadgcc-445e5fbbc093303ce94e4f8031853af2a2d2fd68.tar.gz
* simplify-rtx.c (simplify_binary_operation): Unfactor the shift
and rotate cases. <LSHIFTRT>: Optimize (lshiftrt (clz X) C) as (eq X 0) where C is log2(GET_MODE_BITSIZE(X)) on targets with the appropriate semantics. * gcc.target/ppc-eq0-1.c: New test case. * gcc.target/ppc-negeq0-1.c: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114239 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/simplify-rtx.c28
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.target/powerpc/ppc-eq0-1.c10
-rw-r--r--gcc/testsuite/gcc.target/powerpc/ppc-negeq0-1.c15
5 files changed, 63 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9cb3befcafc..4586d99d140 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2006-05-30 Roger Sayle <roger@eyesopen.com>
+
+ * simplify-rtx.c (simplify_binary_operation): Unfactor the shift
+ and rotate cases.
+ <LSHIFTRT>: Optimize (lshiftrt (clz X) C) as (eq X 0) where C is
+ log2(GET_MODE_BITSIZE(X)) on targets with the appropriate semantics.
+
2006-05-30 Dirk Mueller <dmueller@suse.de>
PR c/27273
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index c51ca9e7017..65b1d193d42 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -2436,21 +2436,45 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode,
case ROTATERT:
case ROTATE:
case ASHIFTRT:
+ if (trueop1 == CONST0_RTX (mode))
+ return op0;
+ if (trueop0 == CONST0_RTX (mode) && ! side_effects_p (op1))
+ return op0;
/* Rotating ~0 always results in ~0. */
if (GET_CODE (trueop0) == CONST_INT && width <= HOST_BITS_PER_WIDE_INT
&& (unsigned HOST_WIDE_INT) INTVAL (trueop0) == GET_MODE_MASK (mode)
&& ! side_effects_p (op1))
return op0;
-
- /* Fall through.... */
+ break;
case ASHIFT:
case SS_ASHIFT:
+ if (trueop1 == CONST0_RTX (mode))
+ return op0;
+ if (trueop0 == CONST0_RTX (mode) && ! side_effects_p (op1))
+ return op0;
+ break;
+
case LSHIFTRT:
if (trueop1 == CONST0_RTX (mode))
return op0;
if (trueop0 == CONST0_RTX (mode) && ! side_effects_p (op1))
return op0;
+ /* Optimize (lshiftrt (clz X) C) as (eq X 0). */
+ if (GET_CODE (op0) == CLZ
+ && GET_CODE (trueop1) == CONST_INT
+ && STORE_FLAG_VALUE == 1
+ && INTVAL (trueop1) < width)
+ {
+ enum machine_mode imode = GET_MODE (XEXP (op0, 0));
+ unsigned HOST_WIDE_INT zero_val = 0;
+
+ if (CLZ_DEFINED_VALUE_AT_ZERO (imode, zero_val)
+ && zero_val == GET_MODE_BITSIZE (imode)
+ && INTVAL (trueop1) == exact_log2 (zero_val))
+ return simplify_gen_relational (EQ, mode, imode,
+ XEXP (op0, 0), const0_rtx);
+ }
break;
case SMIN:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d5b709419be..ecc1cc14f9a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2006-05-30 Roger Sayle <roger@eyesopen.com>
+
+ * gcc.target/ppc-eq0-1.c: New test case.
+ * gcc.target/ppc-negeq0-1.c: New test case.
+
2006-05-30 Dirk Mueller <dmueller@suse.de>
PR c/27273
diff --git a/gcc/testsuite/gcc.target/powerpc/ppc-eq0-1.c b/gcc/testsuite/gcc.target/powerpc/ppc-eq0-1.c
new file mode 100644
index 00000000000..163a4b9925a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/ppc-eq0-1.c
@@ -0,0 +1,10 @@
+/* PR rtl-optimization/10588 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int foo(int x)
+{
+ return x == 0;
+}
+
+/* { dg-final { scan-assembler "cntlzw" } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/ppc-negeq0-1.c b/gcc/testsuite/gcc.target/powerpc/ppc-negeq0-1.c
new file mode 100644
index 00000000000..37d10bc5b68
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/ppc-negeq0-1.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int foo(int x)
+{
+ return -(x == 0);
+}
+
+int bar(int x)
+{
+ int t = __builtin_clz(x);
+ return -(t>>5);
+}
+
+/* { dg-final { scan-assembler-not "cntlzw" } } */