From 12430896397b7477294814403674d75e668f9f22 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Thu, 16 Jun 2011 08:41:50 +0000 Subject: [PATCH] gimple.c (canonicalize_cond_expr_cond): (bool)x is not the same as x != 0. 2011-06-16 Richard Guenther * gimple.c (canonicalize_cond_expr_cond): (bool)x is not the same as x != 0. * fold-const.c (fold_binary_loc): Do not fold X & 1 != 0 to (bool) X & 1. * ipa-prop.c (ipa_analyze_indirect_call_uses): Also allow equality compares against zero for the lower bit. From-SVN: r175096 --- gcc/ChangeLog | 9 +++++++++ gcc/fold-const.c | 8 -------- gcc/gimple.c | 10 +--------- gcc/ipa-prop.c | 3 ++- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7a5a4114c2d..46ef4576385 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2011-06-16 Richard Guenther + + * gimple.c (canonicalize_cond_expr_cond): (bool)x is not + the same as x != 0. + * fold-const.c (fold_binary_loc): Do not fold X & 1 != 0 to + (bool) X & 1. + * ipa-prop.c (ipa_analyze_indirect_call_uses): Also allow + equality compares against zero for the lower bit. + 2011-06-16 Jakub Jelinek PR tree-optimization/49419 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index e1a497eda96..c39d33e1da2 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -12357,14 +12357,6 @@ fold_binary_loc (location_t loc, } } - /* If this is an NE comparison of zero with an AND of one, remove the - comparison since the AND will give the correct value. */ - if (code == NE_EXPR - && integer_zerop (arg1) - && TREE_CODE (arg0) == BIT_AND_EXPR - && integer_onep (TREE_OPERAND (arg0, 1))) - return fold_convert_loc (loc, type, arg0); - /* If we have (A & C) == C where C is a power of 2, convert this into (A & C) != 0. Similarly for NE_EXPR. */ if (TREE_CODE (arg0) == BIT_AND_EXPR diff --git a/gcc/gimple.c b/gcc/gimple.c index 6a9b58d6023..fd9757908f0 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -3139,16 +3139,8 @@ canonicalize_cond_expr_cond (tree t) && truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))) t = TREE_OPERAND (t, 0); - /* For (bool)x use x != 0. */ - if (CONVERT_EXPR_P (t) - && TREE_CODE (TREE_TYPE (t)) == BOOLEAN_TYPE) - { - tree top0 = TREE_OPERAND (t, 0); - t = build2 (NE_EXPR, TREE_TYPE (t), - top0, build_int_cst (TREE_TYPE (top0), 0)); - } /* For !x use x == 0. */ - else if (TREE_CODE (t) == TRUTH_NOT_EXPR) + if (TREE_CODE (t) == TRUTH_NOT_EXPR) { tree top0 = TREE_OPERAND (t, 0); t = build2 (EQ_EXPR, TREE_TYPE (t), diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index f7bb3114ba6..10c11d41ae6 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1347,7 +1347,8 @@ ipa_analyze_indirect_call_uses (struct cgraph_node *node, if (!branch || gimple_code (branch) != GIMPLE_COND) return; - if (gimple_cond_code (branch) != NE_EXPR + if ((gimple_cond_code (branch) != NE_EXPR + && gimple_cond_code (branch) != EQ_EXPR) || !integer_zerop (gimple_cond_rhs (branch))) return; -- 2.30.2