Hi!

The parloops code when walking over PHI arguments from the loop exit
edge assumes that the arguments must be SSA_NAMEs, without checking.
As can be seen on the following testcase, in some cases it can be a constant
as well.  And we don't really need to do anything special in those cases,
the constant can remain even when the loop is parallelized.

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

2019-04-24  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/90211
        * tree-parloops.c (try_create_reduction_list): Ignore phi arguments
        which are not SSA_NAMEs.

        * gcc.dg/autopar/pr90211.c: New test.

--- gcc/tree-parloops.c.jj      2019-02-26 14:13:08.297824084 +0100
+++ gcc/tree-parloops.c 2019-04-23 12:35:13.253037933 +0200
@@ -2794,7 +2794,7 @@ try_create_reduction_list (loop_p loop,
       gimple *reduc_phi;
       tree val = PHI_ARG_DEF_FROM_EDGE (phi, exit);
 
-      if (!virtual_operand_p (val))
+      if (TREE_CODE (val) == SSA_NAME && !virtual_operand_p (val))
        {
          if (dump_file && (dump_flags & TDF_DETAILS))
            {
--- gcc/testsuite/gcc.dg/autopar/pr90211.c.jj   2019-04-23 12:56:30.426338537 
+0200
+++ gcc/testsuite/gcc.dg/autopar/pr90211.c      2019-04-23 12:29:12.747882701 
+0200
@@ -0,0 +1,24 @@
+/* PR tree-optimization/90211 */
+/* { dg-do compile } */
+/* { dg-require-effective-target pthread } */
+/* { dg-options "-O3 -fassociative-math -ftree-parallelize-loops=2 
-fno-signed-zeros -fno-trapping-math -fno-tree-copy-prop" } */
+
+double
+foo (int x)
+{
+  double a, b = 0.0;
+  while (x < 3)
+    {
+      int c;
+      a = 0.0;
+      c = 0;
+      while (c < x)
+        {
+          a += 1.0;
+          ++c;
+        }
+      b += 1.0;
+      ++x;
+    }
+  return a + b;
+}

        Jakub

Reply via email to