This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[tree-ssa] [PATCH] fix PR 13066, fold being stupid


The problem is that now we require that TRUTH_*_EXPR's arguments to be of type of boolean but
when we build the tree in fold, we do not test for the type at all.


There are two ways to fix this bug, either by calling fold_convert or by not folding it in the
first place if the types are not boolean type, both produce the same code but the one which
does not fold uses less memory both on the tree level and the RTL level.


I prefer the not folding patch as it is a memory savings one unless someone can prove me wrong.




Thanks, Andrew Pinski




Calling fold_convert patch:


	* fold-const (fold): Call fold_convert when building
	a TRUTH_*_EXPR tree.


Index: fold-const.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v retrieving revision 1.213.2.75 diff -u -p -r1.213.2.75 fold-const.c --- fold-const.c 27 Feb 2004 21:50:48 -0000 1.213.2.75 +++ fold-const.c 29 Feb 2004 02:03:52 -0000 @@ -5493,7 +5493,8 @@ fold (tree expr) t = fold (build (code == BIT_AND_EXPR ? TRUTH_AND_EXPR : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR : TRUTH_XOR_EXPR, - type, arg0, arg1)); + type, fold_convert (boolean_type_node, arg0), + fold_convert (boolean_type_node, arg1)));

       if (code == EQ_EXPR)
 	t = invert_truthvalue (t);

Not building the tree patch:

	* fold-const.c (fold): Do not build the TRUTH_*_EXPR tree if
	the argument trees are not boolean type.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.75
diff -u -p -r1.213.2.75 fold-const.c
--- fold-const.c 27 Feb 2004 21:50:48 -0000 1.213.2.75
+++ fold-const.c 29 Feb 2004 01:39:23 -0000
@@ -5477,7 +5477,10 @@ fold (tree expr)
BIT_AND_EXPR with the constant 1, or a truth value. In that case, the
code below would make the expression more complex. Change it to a
TRUTH_{AND,OR}_EXPR. Likewise, convert a similar NE_EXPR to
- TRUTH_XOR_EXPR and an EQ_EXPR to the inversion of a TRUTH_XOR_EXPR. */
+ TRUTH_XOR_EXPR and an EQ_EXPR to the inversion of a TRUTH_XOR_EXPR.
+
+ Since TRUTH_*_EXPR requires that the types of the arguments to be
+ boolean types check that also. */


   if ((code == BIT_AND_EXPR || code == BIT_IOR_EXPR
        || code == EQ_EXPR || code == NE_EXPR)
@@ -5488,7 +5491,9 @@ fold (tree expr)
 	  || (truth_value_p (TREE_CODE (arg1))
 	      && (truth_value_p (TREE_CODE (arg0))
 		  || (TREE_CODE (arg0) == BIT_AND_EXPR
-		      && integer_onep (TREE_OPERAND (arg0, 1)))))))
+		      && integer_onep (TREE_OPERAND (arg0, 1))))))
+      && TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE
+      && TREE_CODE (TREE_TYPE (arg1)) == BOOLEAN_TYPE)
     {
       t = fold (build (code == BIT_AND_EXPR ? TRUTH_AND_EXPR
 		       : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]