aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2004-03-07 20:13:50 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2004-03-07 20:13:50 +0000
commitcd2f1c7a623809b0b7e2b224e1240fb74f5f0767 (patch)
tree92143fa659d22e48620905f9ea1ee62d1875d469
parent350f4ea897ebddd78030dbb18e4876deac235490 (diff)
downloadgcc-cd2f1c7a623809b0b7e2b224e1240fb74f5f0767.zip
gcc-cd2f1c7a623809b0b7e2b224e1240fb74f5f0767.tar.gz
gcc-cd2f1c7a623809b0b7e2b224e1240fb74f5f0767.tar.bz2
fold-const.c (fold): Fold x | x as x.
* fold-const.c (fold) <IOR_EXPR>: Fold x | x as x. <XOR_EXPR>: Fold x ^ x as zero. <AND_EXPR>: Fold x & x as x. From-SVN: r79065
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c6
2 files changed, 12 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2094b29..b0c115e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@
2004-03-07 Roger Sayle <roger@eyesopen.com>
+ * fold-const.c (fold) <IOR_EXPR>: Fold x | x as x.
+ <XOR_EXPR>: Fold x ^ x as zero.
+ <AND_EXPR>: Fold x & x as x.
+
+2004-03-07 Roger Sayle <roger@eyesopen.com>
+
* fold-const.c (fold) <EQ_EXPR>: Rewrite optimization to transform
"foo++ == const" into "++foo == const+incr".
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 042cd9e..bbef4e6 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6605,6 +6605,8 @@ fold (tree expr)
return omit_one_operand (type, arg1, arg0);
if (integer_zerop (arg1))
return non_lvalue (fold_convert (type, arg0));
+ if (operand_equal_p (arg0, arg1, 0))
+ return non_lvalue (fold_convert (type, arg0));
t1 = distribute_bit_expr (code, type, arg0, arg1);
if (t1 != NULL_TREE)
return t1;
@@ -6633,6 +6635,8 @@ fold (tree expr)
return non_lvalue (fold_convert (type, arg0));
if (integer_all_onesp (arg1))
return fold (build1 (BIT_NOT_EXPR, type, arg0));
+ if (operand_equal_p (arg0, arg1, 0))
+ return omit_one_operand (type, integer_zero_node, arg0);
/* If we are XORing two BIT_AND_EXPR's, both of which are and'ing
with a constant, and the two constants have no bits in common,
@@ -6659,6 +6663,8 @@ fold (tree expr)
return non_lvalue (fold_convert (type, arg0));
if (integer_zerop (arg1))
return omit_one_operand (type, arg1, arg0);
+ if (operand_equal_p (arg0, arg1, 0))
+ return non_lvalue (fold_convert (type, arg0));
t1 = distribute_bit_expr (code, type, arg0, arg1);
if (t1 != NULL_TREE)
return t1;