diff mbox series

Fix PR82819

Message ID alpine.LSU.2.20.1801231421570.32271@zhemvz.fhfr.qr
State New
Headers show
Series Fix PR82819 | expand

Commit Message

Richard Biener Jan. 23, 2018, 1:23 p.m. UTC
This fixes a GRAPHITE code-generation issue by eliding ISL AST plus
for large power-of-two values that don't affect the result.
I intentionally didn't extend this to other values with the same
property as I'd like to see testcases.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2018-01-23  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/82819
	* graphite-isl-ast-to-gimple.c (binary_op_to_tree): Avoid
	code generating pluses that are no-ops in the target precision.

	* gcc.dg/graphite/pr82819.c: New testcase.
diff mbox series

Patch

Index: gcc/graphite-isl-ast-to-gimple.c
===================================================================
--- gcc/graphite-isl-ast-to-gimple.c	(revision 256977)
+++ gcc/graphite-isl-ast-to-gimple.c	(working copy)
@@ -326,7 +326,8 @@  binary_op_to_tree (tree type, __isl_take
   /* From our constraint generation we may get modulo operations that
      we cannot represent explicitely but that are no-ops for TYPE.
      Elide those.  */
-  if (expr_type == isl_ast_op_pdiv_r
+  if ((expr_type == isl_ast_op_pdiv_r
+       || expr_type == isl_ast_op_add)
       && isl_ast_expr_get_type (arg_expr) == isl_ast_expr_int
       && (wi::exact_log2 (widest_int_from_isl_expr_int (arg_expr))
 	  >= TYPE_PRECISION (type)))
Index: gcc/testsuite/gcc.dg/graphite/pr82819.c
===================================================================
--- gcc/testsuite/gcc.dg/graphite/pr82819.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/graphite/pr82819.c	(working copy)
@@ -0,0 +1,22 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -floop-nest-optimize" } */
+
+short int *ts;
+
+void
+c2 (unsigned long long int s4, int ns)
+{
+  short int *b2 = (short int *)&ns;
+
+  while (ns != 0)
+    {
+      int xn;
+
+      for (xn = 0; xn < 3; ++xn)
+	for (*b2 = 0; *b2 < 2; ++*b2)
+	  s4 += xn;
+      if (s4 != 0)
+	b2 = ts;
+      ++ns;
+    }
+}