The following backports a correctness fix I slipped in during some
refactoring in the GCC 6 dev phase.

Bootstrap and regtest running on x86_64-unknown-linux-gnu, meanwhile
applied the testcase to trunk and GCC 6.

Richard.

2016-09-27  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/77478
        * tree-vect-loop-manip.c (vect_gen_niters_for_prolog_loop):
        Fix alignment of SSA var used before the alignment prologue.

        * gcc.dg/torture/pr77478.c: New testcase.

Index: gcc/tree-vect-loop-manip.c
===================================================================
--- gcc/tree-vect-loop-manip.c  (revision 240417)
+++ gcc/tree-vect-loop-manip.c  (working copy)
@@ -1886,7 +1886,7 @@ vect_gen_niters_for_prolog_loop (loop_ve
       gimple_seq new_stmts = NULL;
       bool negative = tree_int_cst_compare (DR_STEP (dr), size_zero_node) < 0;
       tree offset = negative
-         ? size_int (-TYPE_VECTOR_SUBPARTS (vectype) + 1) : NULL_TREE;
+         ? size_int (-TYPE_VECTOR_SUBPARTS (vectype) + 1) : size_zero_node;
       tree start_addr = vect_create_addr_base_for_vector_ref (dr_stmt,
                                                &new_stmts, offset, loop);
       tree type = unsigned_type_for (TREE_TYPE (start_addr));
Index: gcc/testsuite/gcc.dg/torture/pr77478.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr77478.c      (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr77478.c      (working copy)
@@ -0,0 +1,22 @@
+/* { dg-do run } */
+/* { dg-additional-options "-ffast-math" } */
+
+static const float A[10] = {1};
+
+float
+foo(float *f, int n)
+{
+  int i, j;
+  float a = 0, b = 0;
+  for (i = n/2; i < n; i++)
+    a += f[i]*.1f;
+  for (i = n/2, j = 0; i < n; i++, j++)
+    b += f[i]*A[j]+a*A[j];
+  return b;
+}
+
+int main()
+{
+  float a[21] = {0};
+  return foo(a+1, 20) + foo(a, 20);
+}

Reply via email to