summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>2003-09-29 17:35:11 +0000
committerkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>2003-09-29 17:35:11 +0000
commit79e45861c136c36ff36f734b217510c9f736f393 (patch)
tree0f7ea83bcc8f21bb26c3a1a6dd61d42a9f950cb5
parent88e1c3026b07ba880d080b3739c58873f982917b (diff)
downloadppe42-gcc-79e45861c136c36ff36f734b217510c9f736f393.tar.gz
ppe42-gcc-79e45861c136c36ff36f734b217510c9f736f393.zip
* fold-const.c (fold): Fold (A & ~B) - (A & B) into
(A ^ B) - B, where B is any power of 2 minus 1. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71910 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c23
2 files changed, 28 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 96a7ad4fa65..307e9b76fd9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2003-09-29 Kazu Hirata <kazu@cs.umass.edu>
+
+ * fold-const.c (fold): Fold (A & ~B) - (A & B) into
+ (A ^ B) - B, where B is any power of 2 minus 1.
+
Mon Sep 29 19:05:46 CEST 2003 Jan Hubicka <jh@suse.cz>
* libgcov.c (gcov_exit): Fix two pastos.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 96d46263df2..3cfa5454360 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6017,6 +6017,29 @@ fold (tree expr)
TREE_OPERAND (arg1, 1))),
arg0));
}
+
+ /* Fold (A & ~B) - (A & B) into (A ^ B) - B, , where B is
+ any power of 2 minus 1. */
+ if (TREE_CODE (arg0) == BIT_AND_EXPR
+ && TREE_CODE (arg1) == BIT_AND_EXPR
+ && operand_equal_p (TREE_OPERAND (arg0, 0),
+ TREE_OPERAND (arg1, 0), 0)
+ && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
+ && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST)
+ {
+ tree mask0 = TREE_OPERAND (arg0, 1);
+ tree mask1 = TREE_OPERAND (arg1, 1);
+ tree tem = fold (build1 (BIT_NOT_EXPR, type, mask0));
+
+ if (operand_equal_p (tem, mask1, 0)
+ && integer_pow2p (fold (build (PLUS_EXPR, type,
+ mask1, integer_one_node))))
+ {
+ tem = fold (build (BIT_XOR_EXPR, type,
+ TREE_OPERAND (arg0, 0), mask1));
+ return fold (build (MINUS_EXPR, type, tem, mask1));
+ }
+ }
}
/* See if ARG1 is zero and X - ARG1 reduces to X. */
OpenPOWER on IntegriCloud