re PR target/60693 (ICE on funny memcpy)
[gcc.git] / gcc / omp-low.c
index 900c1ba221ccfef8476fd922e610e1bf67c07db4..11bb2d35a151aa0b563254d2148d00fd163f466a 100644 (file)
@@ -2929,6 +2929,7 @@ omp_max_vf (void)
 {
   if (!optimize
       || optimize_debug
+      || !flag_tree_loop_optimize
       || (!flag_tree_loop_vectorize
          && (global_options_set.x_flag_tree_loop_vectorize
               || global_options_set.x_flag_tree_vectorize)))
@@ -3671,7 +3672,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
       /* Don't add any barrier for #pragma omp simd or
         #pragma omp distribute.  */
       if (gimple_code (ctx->stmt) != GIMPLE_OMP_FOR
-         || gimple_omp_for_kind (ctx->stmt) & GF_OMP_FOR_KIND_FOR)
+         || gimple_omp_for_kind (ctx->stmt) == GF_OMP_FOR_KIND_FOR)
        gimple_seq_add_stmt (ilist, build_omp_barrier (NULL_TREE));
     }
 
@@ -6839,6 +6840,7 @@ expand_omp_simd (struct omp_region *region, struct omp_for_data *fd)
       if ((flag_tree_loop_vectorize
           || (!global_options_set.x_flag_tree_loop_vectorize
                && !global_options_set.x_flag_tree_vectorize))
+         && flag_tree_loop_optimize
          && loop->safelen > 1)
        {
          loop->force_vect = true;
@@ -8946,8 +8948,14 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   if (!gimple_seq_empty_p (omp_for_body)
       && gimple_code (gimple_seq_first_stmt (omp_for_body)) == GIMPLE_BIND)
     {
-      tree vars = gimple_bind_vars (gimple_seq_first_stmt (omp_for_body));
+      gimple inner_bind = gimple_seq_first_stmt (omp_for_body);
+      tree vars = gimple_bind_vars (inner_bind);
       gimple_bind_append_vars (new_stmt, vars);
+      /* bind_vars/BLOCK_VARS are being moved to new_stmt/block, don't
+        keep them on the inner_bind and it's block.  */
+      gimple_bind_set_vars (inner_bind, NULL_TREE);
+      if (gimple_bind_block (inner_bind))
+       BLOCK_VARS (gimple_bind_block (inner_bind)) = NULL_TREE;
     }
 
   if (gimple_omp_for_combined_into_p (stmt))
@@ -9806,6 +9814,13 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
                                        TREE_VEC_ELT (t, 1)),
                                &initlist, true, NULL_TREE);
          gimple_seq_add_seq (&ilist, initlist);
+
+         tree clobber = build_constructor (TREE_TYPE (TREE_VEC_ELT (t, 1)),
+                                           NULL);
+         TREE_THIS_VOLATILE (clobber) = 1;
+         gimple_seq_add_stmt (&olist,
+                              gimple_build_assign (TREE_VEC_ELT (t, 1),
+                                                   clobber));
        }
 
       tree clobber = build_constructor (ctx->record_type, NULL);
@@ -10109,7 +10124,20 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx)
       if ((ctx || task_shared_vars)
          && walk_gimple_op (stmt, lower_omp_regimplify_p,
                             ctx ? NULL : &wi))
-       gimple_regimplify_operands (stmt, gsi_p);
+       {
+         /* Just remove clobbers, this should happen only if we have
+            "privatized" local addressable variables in SIMD regions,
+            the clobber isn't needed in that case and gimplifying address
+            of the ARRAY_REF into a pointer and creating MEM_REF based
+            clobber would create worse code than we get with the clobber
+            dropped.  */
+         if (gimple_clobber_p (stmt))
+           {
+             gsi_replace (gsi_p, gimple_build_nop (), true);
+             break;
+           }
+         gimple_regimplify_operands (stmt, gsi_p);
+       }
       break;
     }
 }
@@ -10121,9 +10149,8 @@ lower_omp (gimple_seq *body, omp_context *ctx)
   gimple_stmt_iterator gsi;
   for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi))
     lower_omp_1 (&gsi, ctx);
-  /* Inside target region we haven't called fold_stmt during gimplification,
-     because it can break code by adding decl references that weren't in the
-     source.  Call fold_stmt now.  */
+  /* During gimplification, we have not always invoked fold_stmt
+     (gimplify.c:maybe_fold_stmt); call it now.  */
   if (target_nesting_level)
     for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi))
       fold_stmt (&gsi);
@@ -10263,7 +10290,8 @@ diagnose_sb_0 (gimple_stmt_iterator *gsi_p,
       if ((branch_ctx
           && gimple_code (branch_ctx) == GIMPLE_OMP_FOR
           && gimple_omp_for_kind (branch_ctx) == GF_OMP_FOR_KIND_CILKSIMD)
-         || (gimple_code (label_ctx) == GIMPLE_OMP_FOR
+         || (label_ctx
+             && gimple_code (label_ctx) == GIMPLE_OMP_FOR
              && gimple_omp_for_kind (label_ctx) == GF_OMP_FOR_KIND_CILKSIMD))
        cilkplus_block = true;
     }
@@ -10649,7 +10677,7 @@ simd_clone_struct_alloc (int nargs)
   size_t len = (sizeof (struct cgraph_simd_clone)
                + nargs * sizeof (struct cgraph_simd_clone_arg));
   clone_info = (struct cgraph_simd_clone *)
-              ggc_internal_cleared_alloc_stat (len PASS_MEM_STAT);
+              ggc_internal_cleared_alloc (len);
   return clone_info;
 }
 
@@ -11694,7 +11722,6 @@ expand_simd_clones (struct cgraph_node *node)
          if (i != 0)
            {
              clone = simd_clone_struct_alloc (clone_info->nargs
-                                              - clone_info->inbranch
                                               + ((i & 1) != 0));
              simd_clone_struct_copy (clone, clone_info);
              /* Undo changes targetm.simd_clone.compute_vecsize_and_simdlen