aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKazu Hirata <kazu@cs.umass.edu>2003-03-20 16:10:36 +0000
committerKazu Hirata <kazu@gcc.gnu.org>2003-03-20 16:10:36 +0000
commit015c318662801cd61e48698362d3d11151fbfdfa (patch)
treefebe4386bb8881ee4e27be3b484e32721d352557 /gcc
parent101cb92aa6a16a51b5011cca84e2d2d1600cad4e (diff)
downloadgcc-015c318662801cd61e48698362d3d11151fbfdfa.zip
gcc-015c318662801cd61e48698362d3d11151fbfdfa.tar.gz
gcc-015c318662801cd61e48698362d3d11151fbfdfa.tar.bz2
* fold-const.c (fold): Fold A - (A & B) into ~B & A.
From-SVN: r64615
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/fold-const.c16
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0f58a3f..d20b175 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2003-03-20 Kazu Hirata <kazu at cs dot umass dot edu>
+
+ * fold-const.c (fold): Fold A - (A & B) into ~B & A.
+
2003-03-20 Kazu Hirata <kazu@cs.umass.edu>
* config/h8300/h8300.md (a peephole2): New.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 48c3683..4890c17 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -5560,6 +5560,22 @@ fold (expr)
TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0))),
TREE_OPERAND (arg0, 1)));
+
+ /* Fold A - (A & B) into ~B & A. */
+ if (!TREE_SIDE_EFFECTS (arg0)
+ && TREE_CODE (arg1) == BIT_AND_EXPR)
+ {
+ if (operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0))
+ return fold (build (BIT_AND_EXPR, type,
+ fold (build1 (BIT_NOT_EXPR, type,
+ TREE_OPERAND (arg1, 0))),
+ arg0));
+ if (operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
+ return fold (build (BIT_AND_EXPR, type,
+ fold (build1 (BIT_NOT_EXPR, type,
+ TREE_OPERAND (arg1, 1))),
+ arg0));
+ }
}
/* See if ARG1 is zero and X - ARG1 reduces to X. */