Patchwork Fold to more canonical TRUHT_NOT_EXPRs

login
register
mail settings
Submitter Richard Guenther
Date July 14, 2011, 12:39 p.m.
Message ID <alpine.LNX.2.00.1107141438080.810@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/104670/
State New
Headers show

Comments

Richard Guenther - July 14, 2011, 12:39 p.m.
The following generates boolean-typed TRUTH_NOT_EXPRs instead of
operating on converted boolean operands.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

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.

Patch

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 176266)
+++ gcc/fold-const.c	(working copy)
@@ -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)