This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] fold-const.c: Fold A - (A & B) into ~B & A.
Hi Richard,
> Looks ok, except that we should make sure this can never be applied
> to floating-point operands. I don't think we would ever see a
> BIT_AND_EXPR if it's floating point, but since we already have a
> block of code a few lines earlier that is conditional on
> !FLOAT_TYPE_P (type) I think this code should go there as well.
Thanks. I guess it's never wrong to be explicitly safe. Here is the
final patch that I committed.
Kazu Hirata
2003-03-20 Kazu Hirata <kazu at cs dot umass dot edu>
* fold-const.c (fold): Fold A - (A & B) into ~B & A.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.238
diff -u -r1.238 fold-const.c
--- fold-const.c 22 Feb 2003 04:16:16 -0000 1.238
+++ fold-const.c 20 Mar 2003 16:06:00 -0000
@@ -5560,6 +5560,22 @@
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. */