fold-const.c (fold_binary_loc): Convert the !bool_var result...
authorRichard Guenther <rguenther@suse.de>
Thu, 14 Jul 2011 12:42:17 +0000 (12:42 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 14 Jul 2011 12:42:17 +0000 (12:42 +0000)
2011-07-14  Richard Guenther  <rguenther@suse.de>

* fold-const.c (fold_binary_loc): Convert the !bool_var result,
not bool_var when folding bool_var != 1 or bool_var == 0.

From-SVN: r176272

gcc/ChangeLog
gcc/fold-const.c

index 2341964fe701bfe2c321c9266ae3d7d3ee0e8226..61b45357296095cfcabf4607103674e76f02a07a 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-14  Richard Guenther  <rguenther@suse.de>
+
+       * fold-const.c (fold_binary_loc): Convert the !bool_var result,
+       not bool_var when folding bool_var != 1 or bool_var == 0.
+
 2011-07-14  Bernd Schmidt  <bernds@codesourcery.com>
 
        * haifa-sched.c (schedule_insns): Remove outdated comment.
index 9640264954a2e75063e4107543f674194d5ab7c8..94c8926b03da2c6e7690d4b7e570eca2d031db3b 100644 (file)
@@ -12156,14 +12156,16 @@ fold_binary_loc (location_t loc,
       /* bool_var != 1 becomes !bool_var. */
       if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1)
           && code == NE_EXPR)
-        return fold_build1_loc (loc, TRUTH_NOT_EXPR, type,
-                           fold_convert_loc (loc, type, arg0));
+        return fold_convert_loc (loc, type,
+                                fold_build1_loc (loc, TRUTH_NOT_EXPR,
+                                                 TREE_TYPE (arg0), arg0));
 
       /* bool_var == 0 becomes !bool_var. */
       if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)
           && code == EQ_EXPR)
-        return fold_build1_loc (loc, TRUTH_NOT_EXPR, type,
-                           fold_convert_loc (loc, type, arg0));
+        return fold_convert_loc (loc, type,
+                                fold_build1_loc (loc, TRUTH_NOT_EXPR,
+                                                 TREE_TYPE (arg0), arg0));
 
       /* !exp != 0 becomes !exp */
       if (TREE_CODE (arg0) == TRUTH_NOT_EXPR && integer_zerop (arg1)