aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorAndrew Pinski <pinskia@physics.uc.edu>2005-11-25 04:54:59 +0000
committerAndrew Pinski <pinskia@gcc.gnu.org>2005-11-24 20:54:59 -0800
commit210dfe6eccfaba41bf3860963b023a30c276dcbc (patch)
treece051b7b6a061d6d5ab22d134d04e47bb4ba286b /gcc/fold-const.c
parent4ca6f88ae88df2e1a41c728d2ced1763b026c854 (diff)
downloadgcc-210dfe6eccfaba41bf3860963b023a30c276dcbc.zip
gcc-210dfe6eccfaba41bf3860963b023a30c276dcbc.tar.gz
gcc-210dfe6eccfaba41bf3860963b023a30c276dcbc.tar.bz2
[multiple changes]
2005-11-25 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/24990 * fold-const.c (fold_binary): Fold (~a) == C to a == ~C for C being INTEGER_CST. Likewise for !=. 2005-11-24 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/24990 * tree-ssa/pr24990-1.c: New test. From-SVN: r107487
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 2d750f6..962ebd3 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8839,6 +8839,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
/* If one arg is a real or integer constant, put it last. */
if (tree_swap_operands_p (arg0, arg1, true))
return fold_build2 (swap_tree_comparison (code), type, op1, op0);
+
+ /* ~a != C becomes a != ~C where C is a constant. Likewise for ==. */
+ if (TREE_CODE (arg0) == BIT_NOT_EXPR && TREE_CODE (arg1) == INTEGER_CST
+ && (code == NE_EXPR || code == EQ_EXPR))
+ return fold_build2 (code, type, TREE_OPERAND (arg0, 0),
+ fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1),
+ arg1));
/* bool_var != 0 becomes bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)