Hi!

As the testcase shows, even result of force_gimple_operand_gsi
might need regimplification, e.g. if it is ADDR_EXPR of a reference with
a decl with DECL_VALUE_EXPR set.

Fixed thusly.  Additionally, I've noticed the OpenMP 4.5 support broke a
case where we assigned to addressable decl vback some expression and then
wanted to use that t expression rather than vback to avoid having
addressable decl in there, but 4.5 addition inserted code in between that
reused the temporary for something else.  Haven't managed to construct a
testcase quickly for that though.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2018-12-21  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/85594
        PR middle-end/88553
        * omp-expand.c (extract_omp_for_update_vars): Regimplify the condition
        if needed.
        (expand_omp_for_generic): Don't clobber t temporary for ordered loops.

        * gcc.dg/gomp/pr85594.c: New test.
        * gcc.dg/gomp/pr88553.c: New test.

--- gcc/omp-expand.c.jj 2018-11-19 14:43:35.710901282 +0100
+++ gcc/omp-expand.c    2018-12-21 16:33:21.732632819 +0100
@@ -2076,6 +2076,11 @@ extract_omp_for_update_vars (struct omp_
          t = fold_build2 (fd->loops[i].cond_code, boolean_type_node, v, t);
          stmt = gimple_build_cond_empty (t);
          gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
+         if (walk_tree (gimple_cond_lhs_ptr (as_a <gcond *> (stmt)),
+                        expand_omp_regimplify_p, NULL, NULL)
+             || walk_tree (gimple_cond_rhs_ptr (as_a <gcond *> (stmt)),
+                           expand_omp_regimplify_p, NULL, NULL))
+           gimple_regimplify_operands (stmt, &gsi);
          e = make_edge (bb, body_bb, EDGE_TRUE_VALUE);
          e->probability = profile_probability::guessed_always ().apply_scale 
(7, 8);
        }
@@ -3209,20 +3214,21 @@ expand_omp_for_generic (struct omp_regio
 
          if (fd->ordered && counts[fd->collapse - 1] == NULL_TREE)
            {
+             tree tem;
              if (fd->collapse > 1)
-               t = fd->loop.v;
+               tem = fd->loop.v;
              else
                {
-                 t = fold_build2 (MINUS_EXPR, TREE_TYPE (fd->loops[0].v),
-                                  fd->loops[0].v, fd->loops[0].n1);
-                 t = fold_convert (fd->iter_type, t);
+                 tem = fold_build2 (MINUS_EXPR, TREE_TYPE (fd->loops[0].v),
+                                    fd->loops[0].v, fd->loops[0].n1);
+                 tem = fold_convert (fd->iter_type, tem);
                }
              tree aref = build4 (ARRAY_REF, fd->iter_type,
                                  counts[fd->ordered], size_zero_node,
                                  NULL_TREE, NULL_TREE);
-             t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
-                                           true, GSI_SAME_STMT);
-             expand_omp_build_assign (&gsi, aref, t);
+             tem = force_gimple_operand_gsi (&gsi, tem, true, NULL_TREE,
+                                             true, GSI_SAME_STMT);
+             expand_omp_build_assign (&gsi, aref, tem);
            }
 
          t = build2 (fd->loop.cond_code, boolean_type_node,
--- gcc/testsuite/gcc.dg/gomp/pr85594.c.jj      2018-12-21 16:47:08.430529687 
+0100
+++ gcc/testsuite/gcc.dg/gomp/pr85594.c 2018-12-21 16:46:59.682670326 +0100
@@ -0,0 +1,5 @@
+/* PR middle-end/85594 */
+/* { dg-do compile } */
+/* { dg-additional-options "-fwrapv" } */
+
+#include "pr81768-2.c"
--- gcc/testsuite/gcc.dg/gomp/pr88553.c.jj      2018-12-21 16:48:02.930653492 
+0100
+++ gcc/testsuite/gcc.dg/gomp/pr88553.c 2018-12-21 16:48:20.577369790 +0100
@@ -0,0 +1,5 @@
+/* PR middle-end/88553 */
+/* { dg-do compile } */
+/* { dg-additional-options "-O1 -ftree-loop-vectorize -fwrapv" } */
+
+#include "pr81768-2.c"

        Jakub

Reply via email to