This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR 15777, Fold does not always fold sub trees
- From: Andrew Pinski <apinski at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 6 Jul 2004 22:04:12 -0700
- Subject: [PATCH] Fix PR 15777, Fold does not always fold sub trees
I found this bug when I was playing around with my tree combiner
which needs many improvements which I do not have time for right
now.
Basically ((x&1) == 0) == 0 is folded to
(int)((unsigned int)x ^ 1 ^ 1) & 1 when it should just fold it
to be (x & 1) != 0 or (x & 1) depending on the resulting type.
So this patch makes fold, fold the new x ^ 1 expression which fixes
this bug.
OK? Bootstrapped on powerpc-apple-darwin with no regression.
Thanks,
Andrew Pinski
ChangeLog:
* fold-const.c (fold_single_bit_test): Fold the x^1 expression.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.417
diff -u -p -r1.417 fold-const.c
--- fold-const.c 5 Jul 2004 16:44:17 -0000 1.417
+++ fold-const.c 7 Jul 2004 04:58:11 -0000
@@ -5850,8 +5849,8 @@ fold_single_bit_test (enum tree_code cod
inner, size_int (bitnum));
if (code == EQ_EXPR)
- inner = build2 (BIT_XOR_EXPR, intermediate_type,
- inner, integer_one_node);
+ inner = fold (build2 (BIT_XOR_EXPR, intermediate_type,
+ inner, integer_one_node));
/* Put the AND last so it can combine with more things. */
inner = build2 (BIT_AND_EXPR, intermediate_type,