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]

Let tree_single_nonzero_warnv_p use VRP


Hello,

this patches teaches tree_expr_nonzero_warnv_p to handle SSA_NAME using range information and known (non-)zero bits, by delegating to expr_not_equal_to which already knows how to handle all that.

This makes one strict overflow warning disappear. It isn't particularly surprising, since the new code makes tree_expr_nonzero_warnv_p return true without warning (we do not remember if the range information was obtained using strict overflow). In my opinion, improving code generation is more important than this specific warning.

Bootstrap+regtest on powerpc64le-unknown-linux-gnu.

2017-04-24  Marc Glisse  <marc.glisse@inria.fr>

gcc/
	* fold-const.c (tree_single_nonzero_warnv_p): Handle SSA_NAME.

gcc/testsuite/
	* gcc.dg/tree-ssa/cmpmul-1.c: New file.
	* gcc.dg/Wstrict-overflow-18.c: Xfail.

--
Marc Glisse
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 247083)
+++ gcc/fold-const.c	(working copy)
@@ -13405,20 +13405,23 @@ tree_single_nonzero_warnv_p (tree t, boo
 				     &sub_strict_overflow_p)
 	  && tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 2),
 					&sub_strict_overflow_p))
 	{
 	  if (sub_strict_overflow_p)
 	    *strict_overflow_p = true;
 	  return true;
 	}
       break;
 
+    case SSA_NAME:
+      return expr_not_equal_to (t, wi::zero (TYPE_PRECISION (TREE_TYPE (t))));
+
     default:
       break;
     }
   return false;
 }
 
 #define integer_valued_real_p(X) \
   _Pragma ("GCC error \"Use RECURSE for recursive calls\"") 0
 
 #define RECURSE(X) \
Index: gcc/testsuite/gcc.dg/Wstrict-overflow-18.c
===================================================================
--- gcc/testsuite/gcc.dg/Wstrict-overflow-18.c	(revision 247083)
+++ gcc/testsuite/gcc.dg/Wstrict-overflow-18.c	(working copy)
@@ -7,16 +7,16 @@
 struct c { unsigned int a; unsigned int b; };
 extern void bar (struct c *);
 int
 foo (struct c *p)
 {
   int i;
   int sum = 0;
 
   for (i = 0; i < p->a - p->b; ++i)
     {
-      if (i > 0)  /* { dg-warning "signed overflow" "" } */
+      if (i > 0)  /* { dg-warning "signed overflow" "" { xfail *-*-* } } */
 	sum += 2;
       bar (p);
     }
   return sum;
 }
Index: gcc/testsuite/gcc.dg/tree-ssa/cmpmul-1.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/cmpmul-1.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/cmpmul-1.c	(working copy)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+
+int f(int a, int b, int c){
+  c |= 1; // c cannot be 0
+  a *= c;
+  b *= c;
+  return a == b;
+}
+
+/* { dg-final { scan-tree-dump-not "bit_ior_expr" "optimized" } } */

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