diff --git a/gcc/testsuite/gcc.dg/vect/vec-tail-nomask-2.c b/gcc/testsuite/gcc.dg/vect/vec-tail-nomask-2.c
new file mode 100755
index 0000000..47bb4b7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vec-tail-nomask-2.c
@@ -0,0 +1,155 @@
+/* { dg-do run } */
+/* { dg-require-weak "" } */
+/* { dg-additional-options "-ffast-math --param vect-epilogues-nomask=1 -mavx2" { target avx2_runtime } } */
+
+#define SIZE 1023
+#define ALIGN 64
+
+extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size);
+extern void free (void *);
+
+double __attribute__((noinline))
+test_citer (int * __restrict__ a,
+	    long long * __restrict__ b,
+	    float * __restrict__ c,
+	    double * __restrict__ d)
+{
+  double res = 0;
+  int i;
+
+  a = (int *)__builtin_assume_aligned (a, ALIGN);
+  b = (long long *)__builtin_assume_aligned (b, ALIGN);
+  c = (float *)__builtin_assume_aligned (c, ALIGN);
+  d = (double *)__builtin_assume_aligned (d, ALIGN);
+
+  for (i = 0; i < SIZE; i++)
+    {
+      a[i] = c[i] + 1;
+      if (b[i] < 0)
+	res += d[i];
+    }
+
+  return res;
+}
+
+double __attribute__((noinline))
+test_viter (int * __restrict__ a,
+	    long long * __restrict__ b,
+	    float * __restrict__ c,
+	    double * __restrict__ d,
+	    int size)
+{
+  double res = 0;
+  int i;
+
+  a = (int *)__builtin_assume_aligned (a, ALIGN);
+  b = (long long *)__builtin_assume_aligned (b, ALIGN);
+  c = (float *)__builtin_assume_aligned (c, ALIGN);
+  d = (double *)__builtin_assume_aligned (d, ALIGN);
+
+  for (i = 0; i < size; i++)
+    {
+      a[i] = c[i] + 1;
+      if (b[i] < 0)
+	res += d[i];
+    }
+
+  return res;
+}
+
+void __attribute__((noinline))
+init_data (int * __restrict__ a,
+	   long long * __restrict__ b,
+	   float * __restrict__ c,
+	   double * __restrict__ d,
+	   int size)
+{
+  int i;
+  for (i = 0; i < size; i++)
+    {
+      if (i % 2)
+	{
+	  a[i] = 0;
+	  b[i] = i;
+	  c[i] = 2.5;
+	  d[i] = 1;
+	}
+      else
+	{
+	  a[i] = 0;
+	  b[i] = -i;
+	  c[i] = 2.5;
+	  d[i] = -1;
+	}
+      asm volatile("": : :"memory");
+    }
+  a[size] = (int)size;
+  b[size] = (long long)size;
+  c[size] = (float)size;
+  d[size] = (double)size;
+}
+
+void __attribute__((noinline))
+run_test ()
+{
+  int *a;
+  long long *b;
+  float *c;
+  double *d;
+  double res;
+  int i;
+
+  if (posix_memalign ((void **)&a, ALIGN, (SIZE + 1) * sizeof (int)) != 0)
+    return;
+  if (posix_memalign ((void **)&b, ALIGN, (SIZE + 1) * sizeof (long long)) != 0)
+    return;
+  if (posix_memalign ((void **)&c, ALIGN, (SIZE + 1) * sizeof (float)) != 0)
+    return;
+  if (posix_memalign ((void **)&d, ALIGN, (SIZE + 1) * sizeof (double)) != 0)
+    return;
+
+  init_data (a, b, c, d, SIZE);
+  res = test_citer (a, b, c, d);
+  res += SIZE / 2;
+  if (res > 0.01 || res < -0.01)
+    __builtin_abort ();
+  for (i = 0; i < SIZE; i++)
+    if (a[i] != 3)
+      __builtin_abort ();
+  if (a[SIZE] != (int)SIZE
+      || b[SIZE] != (long long)SIZE
+      || c[SIZE] != (float)SIZE
+      || d[SIZE] != (double)SIZE)
+    __builtin_abort ();
+
+  init_data (a, b, c, d, SIZE);
+  res = test_viter (a, b, c, d, SIZE);
+  res += SIZE / 2;
+  if (res > 0.01 || res < -0.01)
+    __builtin_abort ();
+  for (i = 0; i < SIZE; i++)
+    if (a[i] != 3)
+      __builtin_abort ();
+  if (a[SIZE] != (int)SIZE
+      || b[SIZE] != (long long)SIZE
+      || c[SIZE] != (float)SIZE
+      || d[SIZE] != (double)SIZE)
+    __builtin_abort ();
+
+  free (a);
+  free (b);
+  free (c);
+}
+
+int
+main (int argc, const char **argv)
+{
+  if (!posix_memalign)
+    return 0;
+
+  run_test ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "LOOP VECTORIZED \\(VS=32\\)" 2 "vect" { target avx2_runtime } } } */
+/* { dg-final { scan-tree-dump-times "LOOP EPILOGUE COMBINED \\(VS=32\\)" 2 "vect" { target avx2_runtime } } } */
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index 7538c6c..39762cb 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -540,8 +540,8 @@ vectorize_loops (void)
 	     || loop->force_vectorize)
       {
 	loop_vec_info loop_vinfo, orig_loop_vinfo = NULL;
-	gimple *loop_vectorized_call = vect_loop_vectorized_call (loop);
 vectorize_epilogue:
+	gimple *loop_vectorized_call = vect_loop_vectorized_call (loop);
 	vect_location = find_loop_location (loop);
         if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOCATION
 	    && dump_enabled_p ())
