From 015c318662801cd61e48698362d3d11151fbfdfa Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 20 Mar 2003 16:10:36 +0000 Subject: [PATCH] * fold-const.c (fold): Fold A - (A & B) into ~B & A. From-SVN: r64615 --- gcc/ChangeLog | 4 ++++ gcc/fold-const.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0f58a3f87f4..d20b1758a89 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2003-03-20 Kazu Hirata + + * fold-const.c (fold): Fold A - (A & B) into ~B & A. + 2003-03-20 Kazu Hirata * config/h8300/h8300.md (a peephole2): New. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 48c3683f8c2..4890c173e81 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. */