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]

[vta,trunk] don't call floor_log2(0) in tree-vrp


Shortly after I started working on the latest merge to the VTA branch,
started back in December, I ran into a situation in which we got
different compiler output between stage1 and stage2, because the inline
definition was used when optimizing, and the shift left by -1 ==
floor_log2(0) produced different results.

This patch avoids the divergence, ensuring that (i) we negate signed
numbers with the right width, and that (ii) we don't bother calling
floor_log2 and then invoking unspecified behavior.

Unfortunately, I don't remember any more what testcase it was that
triggered this difference.  It appears to me that the only possibility
this could hit is if both operands of a BIT_IOR_EXPR have ranges
containing only the zero value.

Anyhow, here's the patch.  I'm installing it in the VTA branch.  Ok for
trunk?

for  gcc/ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* tree-vrp.c (extract_range_from_binary_expr): Don't shift by
	floor_log2 of zero.  Negate widened zero.

Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c.orig	2008-12-10 02:39:37.000000000 -0200
+++ gcc/tree-vrp.c	2008-12-11 05:05:26.000000000 -0200
@@ -2557,11 +2557,11 @@ extract_range_from_binary_expr (value_ra
 	  ior_max.high = vr0_max.high | vr1_max.high;
 	  if (ior_max.high != 0)
 	    {
-	      ior_max.low = ~0u;
+	      ior_max.low = ~(unsigned HOST_WIDE_INT)0u;
 	      ior_max.high |= ((HOST_WIDE_INT) 1
 			       << floor_log2 (ior_max.high)) - 1;
 	    }
-	  else
+	  else if (ior_max.low != 0)
 	    ior_max.low |= ((unsigned HOST_WIDE_INT) 1u
 			    << floor_log2 (ior_max.low)) - 1;
 

-- 
Alexandre Oliva           http://www.lsd.ic.unicamp.br/~oliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

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