Patchwork Fix PR49177

login
register
mail settings
Submitter Richard Guenther
Date May 27, 2011, 10:29 a.m.
Message ID <alpine.LNX.2.00.1105271229190.810@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/97669/
State New
Headers show

Comments

Richard Guenther - May 27, 2011, 10:29 a.m.
This fixes PR49177 by re-introducing the removed folding in a
correct way.

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

Richard.

2011-05-27  Richard Guenther  <rguenther@suse.de>

	PR middle-end/49177
	* fold-const.c (fold_unary_loc): Fold (T)(A CMP B) to
	A CMP B ? (T) true : (T) false for non-integral types T again.

Patch

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 174321)
+++ gcc/fold-const.c	(working copy)
@@ -7657,11 +7657,19 @@  fold_unary_loc (location_t loc, enum tre
       if (TREE_TYPE (op0) == type)
 	return op0;
 
-      /* If we have (type) (a CMP b) and type is an integral type, return
-         new expression involving the new type.  */
-      if (COMPARISON_CLASS_P (op0) && INTEGRAL_TYPE_P (type))
-	return fold_build2_loc (loc, TREE_CODE (op0), type, TREE_OPERAND (op0, 0),
-			    TREE_OPERAND (op0, 1));
+      if (COMPARISON_CLASS_P (op0))
+	{
+	  /* If we have (type) (a CMP b) and type is an integral type, return
+	     new expression involving the new type.  */
+	  if (INTEGRAL_TYPE_P (type))
+	    return fold_build2_loc (loc, TREE_CODE (op0), type,
+				    TREE_OPERAND (op0, 0),
+				    TREE_OPERAND (op0, 1));
+	  else
+	    return fold_build3_loc (loc, COND_EXPR, type, op0,
+				    fold_convert (type, boolean_true_node),
+				    fold_convert (type, boolean_false_node));
+	}
 
       /* Handle cases of two conversions in a row.  */
       if (CONVERT_EXPR_P (op0))