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]

[PATCH] Fix PR37387, wrong gimple from ifcombine


As we are looking through some conversions we have to makes sure
to re-generate valid types for bit operations.

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

Richard.

2008-09-09  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/37387
	* tree-ssa-ifcombine.c (ifcombine_iforif): Convert the name
	and bits to a common type.

	* gcc.c-torture/compile/pr37387.c: New testcase.

Index: gcc/testsuite/gcc.c-torture/compile/pr37387.c
===================================================================
--- gcc/testsuite/gcc.c-torture/compile/pr37387.c	(revision 0)
+++ gcc/testsuite/gcc.c-torture/compile/pr37387.c	(revision 0)
@@ -0,0 +1,11 @@
+typedef long int Int;
+void FuncMakeConsequencesPres (long *objDefs1)
+{
+  long a = (long)objDefs1;
+  int c = a & 0x01;
+  int b = 0;
+  if (!  ( 13 <= ( c ? 0 : (((int) objDefs1 & 0x02) ? 0 : *objDefs1  ))
+           && b <= 0))
+    ErrorQuit ();
+}
+
Index: gcc/tree-ssa-ifcombine.c
===================================================================
--- gcc/tree-ssa-ifcombine.c	(revision 140137)
+++ gcc/tree-ssa-ifcombine.c	(working copy)
@@ -440,6 +440,25 @@
       else
 	return false;
 
+      /* As we strip non-widening conversions in finding a common
+         name that is tested make sure to end up with an integral
+	 type for building the bit operations.  */
+      if (TYPE_PRECISION (TREE_TYPE (bits1))
+	  >= TYPE_PRECISION (TREE_TYPE (bits2)))
+	{
+	  bits1 = fold_convert (unsigned_type_for (TREE_TYPE (bits1)), bits1);
+	  name1 = fold_convert (TREE_TYPE (bits1), name1);
+	  bits2 = fold_convert (unsigned_type_for (TREE_TYPE (bits2)), bits2);
+	  bits2 = fold_convert (TREE_TYPE (bits1), bits2);
+	}
+      else
+	{
+	  bits2 = fold_convert (unsigned_type_for (TREE_TYPE (bits2)), bits2);
+	  name1 = fold_convert (TREE_TYPE (bits2), name1);
+	  bits1 = fold_convert (unsigned_type_for (TREE_TYPE (bits1)), bits1);
+	  bits1 = fold_convert (TREE_TYPE (bits2), bits1);
+	}
+
       /* Do it.  */
       gsi = gsi_for_stmt (inner_cond);
       t = fold_build2 (BIT_IOR_EXPR, TREE_TYPE (name1), bits1, bits2);


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