Hi!

On the following testcase from the PR, dce2 turns
  # .MEM_21 = PHI <.MEM_20(5), .MEM_4(D)(2)>
into
  # .MEM_21 = PHI <.MEM_21(5), .MEM_4(D)(2)>
because all writes in the loop have been dead code eliminated.
But only the phicprop2 pass much later is able to optimize this
out (by changing all .MEM_21 vuses into .MEM_4(D) vuses and removing
the virtual phi stmt).  In between those passes is if-conversion though,
and that just gives up when it sees it.  I think the test only wants
to detect conditional stores, so the above useless virtual phis
don't really pose a problem to it.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2015-05-29  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/66142
        * tree-if-conv.c (if_convertible_phi_p): Don't give up on
        virtual phis that feed themselves.

        * gcc.dg/vect/pr66142.c: New test.

--- gcc/tree-if-conv.c.jj       2015-05-21 21:16:18.000000000 +0200
+++ gcc/tree-if-conv.c  2015-05-29 11:24:06.726448462 +0200
@@ -594,7 +594,8 @@ if_convertible_phi_p (struct loop *loop,
 
       FOR_EACH_IMM_USE_FAST (use_p, imm_iter, gimple_phi_result (phi))
        {
-         if (gimple_code (USE_STMT (use_p)) == GIMPLE_PHI)
+         if (gimple_code (USE_STMT (use_p)) == GIMPLE_PHI
+             && USE_STMT (use_p) != (gimple) phi)
            {
              if (dump_file && (dump_flags & TDF_DETAILS))
                fprintf (dump_file, "Difficult to handle this virtual phi.\n");
--- gcc/testsuite/gcc.dg/vect/pr66142.c.jj      2015-05-29 11:31:21.563628051 
+0200
+++ gcc/testsuite/gcc.dg/vect/pr66142.c 2015-05-29 11:31:00.000000000 +0200
@@ -0,0 +1,44 @@
+/* PR middle-end/66142 */
+/* { dg-do compile } */
+/* { dg-additional-options "-ffast-math -fopenmp-simd" } */
+/* { dg-additional-options "-mavx" { target avx_runtime } } */
+
+struct A { float x, y; };
+struct B { struct A t, w; };
+
+static inline float
+bar (const struct B *x)
+{
+  struct A r;
+  float b, c, d;
+  r.x = x->t.x;
+  r.y = x->t.y;
+  b = r.x * x->w.x + r.y * x->w.y;
+  c = b + r.x * r.x + r.y * r.y;
+  if (c > 0.0f)
+    return c + 3.0f;
+  return 0.0f;
+}
+
+void
+foo (float *a, float *b, float *c)
+{
+  int i;
+  float z = 0.0f;
+  float u = *a;
+#pragma omp simd
+  for (i = 0; i < 32; i++)
+    {
+      float x = b[i];
+      float y = c[i];
+      struct B r;
+      r.t.x = 1.0f;
+      r.t.y = u;
+      r.w.x = x;
+      r.w.y = y;
+      z += bar (&r);
+    }
+  *a = z;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 1 "vect" 
{ target vect_condition } } } */

        Jakub

Reply via email to