Bootstrapped / tested on x86_64-unknown-linux-gnu, applied.

Richard.

2019-11-29  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/92704
        * tree-if-conv.c (combine_blocks): Deal with virtual PHIs
        in loops performing only loads.

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

Index: gcc/tree-if-conv.c
===================================================================
--- gcc/tree-if-conv.c  (revision 278807)
+++ gcc/tree-if-conv.c  (working copy)
@@ -2624,6 +2624,11 @@ combine_blocks (class loop *loop)
       vphi = get_virtual_phi (bb);
       if (vphi)
        {
+         /* When there's just loads inside the loop a stray virtual
+            PHI merging the uses can appear, update last_vdef from
+            it.  */
+         if (!last_vdef)
+           last_vdef = gimple_phi_arg_def (vphi, 0);
          imm_use_iterator iter;
          use_operand_p use_p;
          gimple *use_stmt;
@@ -2655,6 +2660,10 @@ combine_blocks (class loop *loop)
              if (gimple_vdef (stmt))
                last_vdef = gimple_vdef (stmt);
            }
+         else
+           /* If this is the first load we arrive at update last_vdef
+              so we handle stray PHIs correctly.  */
+           last_vdef = gimple_vuse (stmt);
          if (predicated[i])
            {
              ssa_op_iter i;
Index: gcc/testsuite/gcc.dg/torture/pr92704.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr92704.c      (nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr92704.c      (working copy)
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fexceptions -fnon-call-exceptions -fno-tree-dce 
-ftree-loop-if-convert" } */
+int zr, yx;
+
+void __attribute__ ((simd))
+oj (int rd, int q7)
+{
+  int wo = (__UINTPTR_TYPE__)&rd;
+
+  while (q7 < 1)
+    {
+      int kv;
+      short int v3;
+
+      for (v3 = 0; v3 < 82; v3 += 3)
+        {
+        }
+
+      kv = zr ? 0 : v3;
+      yx = kv < rd;
+      zr = zr && yx;
+      ++q7;
+    }
+}

Reply via email to