aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorAndrew Pinski <pinskia@physics.uc.edu>2005-05-04 01:52:06 +0000
committerAndrew Pinski <pinskia@gcc.gnu.org>2005-05-03 18:52:06 -0700
commita7e1c9287c7fadf9e58521833f846fdb680bd81c (patch)
treecd5155fa594c0f9c4ee084e45679b9adb9a542a1 /gcc/fold-const.c
parentd8be0aabf797319f3395103cb0bed48420c604c2 (diff)
downloadgcc-a7e1c9287c7fadf9e58521833f846fdb680bd81c.zip
gcc-a7e1c9287c7fadf9e58521833f846fdb680bd81c.tar.gz
gcc-a7e1c9287c7fadf9e58521833f846fdb680bd81c.tar.bz2
[multiple changes]
2004-05-03 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/15618 * fold-const.c (fold_widened_comparison): Treat BOOLEAN_TYPE the same as INTEGER_TYPE. (fold_binary): Fold "bool_var != 0" to bool_var. Fold "bool_var == 1" to bool_var. 2005-05-03 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/15618 * gcc.dg/tree-ssa/bool-[1-9].c: New tests. From-SVN: r99207
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 9e9243c..140f940 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6149,7 +6149,8 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
|| TYPE_UNSIGNED (TREE_TYPE (arg0)) == TYPE_UNSIGNED (shorter_type))
&& (TREE_TYPE (arg1_unw) == shorter_type
|| (TREE_CODE (arg1_unw) == INTEGER_CST
- && TREE_CODE (shorter_type) == INTEGER_TYPE
+ && (TREE_CODE (shorter_type) == INTEGER_TYPE
+ || TREE_CODE (shorter_type) == BOOLEAN_TYPE)
&& int_fits_type_p (arg1_unw, shorter_type))))
return fold_build2 (code, type, arg0_unw,
fold_convert (shorter_type, arg1_unw));
@@ -8856,10 +8857,20 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
case LT_EXPR:
case GT_EXPR:
case LE_EXPR:
- case GE_EXPR:
+ case GE_EXPR:
/* 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);
+
+ /* bool_var != 0 becomes bool_var. */
+ if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)
+ && code == NE_EXPR)
+ return non_lvalue (fold_convert (type, arg0));
+
+ /* bool_var == 1 becomes bool_var. */
+ if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1)
+ && code == EQ_EXPR)
+ return non_lvalue (fold_convert (type, arg0));
/* If this is an equality comparison of the address of a non-weak
object against zero, then we know the result. */