re PR middle-end/57089 (ICE in verify_loop_structure, at cfgloop.c:1647)
authorRichard Biener <rguenther@suse.de>
Mon, 29 Apr 2013 11:31:33 +0000 (11:31 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 29 Apr 2013 11:31:33 +0000 (11:31 +0000)
2013-04-29  Richard Biener  <rguenther@suse.de>

PR middle-end/57089
* omp-low.c (expand_omp_taskreg): If the parent function had
a broken loop tree make sure to schedule a fixup for the child
as well.
(expand_omp_for_generic): Properly add loops.
(expand_omp_for_static_nochunk): Likewise.
(expand_omp_for_static_chunk): Likewise.
(expand_omp_for): For the degenerate case fixup loops.
(expand_omp_sections): Fix default bb placement in loops.
(expand_omp_atomic_pipeline): Properly add loops.

* gfortran.dg/gomp/pr57089.f90: New testcase.

From-SVN: r198409

gcc/ChangeLog
gcc/omp-low.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/gomp/pr57089.f90 [new file with mode: 0644]

index d2cd16b91238212242445c77db73d0a498e88ca0..6400403124409e652325b4ce56c438eb5945a659 100644 (file)
@@ -1,3 +1,16 @@
+2013-04-29  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/57089
+       * omp-low.c (expand_omp_taskreg): If the parent function had
+       a broken loop tree make sure to schedule a fixup for the child
+       as well.
+       (expand_omp_for_generic): Properly add loops.
+       (expand_omp_for_static_nochunk): Likewise.
+       (expand_omp_for_static_chunk): Likewise.
+       (expand_omp_for): For the degenerate case fixup loops.
+       (expand_omp_sections): Fix default bb placement in loops.
+       (expand_omp_atomic_pipeline): Properly add loops.
+
 2013-04-29  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        * predict.c: Fix typo in comment above #define PROB_VERY_UNLIKELY.
index 81ae5b4e5c1ca777db2f8ce6eccf3be1dd407e03..bd7e7e689e5cdae35e6c5626de63d90655a49ba8 100644 (file)
@@ -3571,11 +3571,10 @@ expand_omp_taskreg (struct omp_region *region)
       new_bb = move_sese_region_to_fn (child_cfun, entry_bb, exit_bb, block);
       if (exit_bb)
        single_succ_edge (new_bb)->flags = EDGE_FALLTHRU;
-      /* ???  As the OMP expansion process does not update the loop
-         tree of the original function before outlining the region to
-        the new child function we need to discover loops in the child.
-        Arrange for that.  */
-      child_cfun->x_current_loops->state |= LOOPS_NEED_FIXUP;
+      /* When the OMP expansion process cannot guarantee an up-to-date
+         loop tree arrange for the child function to fixup loops.  */
+      if (loops_state_satisfies_p (LOOPS_NEED_FIXUP))
+       child_cfun->x_current_loops->state |= LOOPS_NEED_FIXUP;
 
       /* Remove non-local VAR_DECLs from child_cfun->local_decls list.  */
       num = vec_safe_length (child_cfun->local_decls);
@@ -4148,6 +4147,16 @@ expand_omp_for_generic (struct omp_region *region,
                               recompute_dominator (CDI_DOMINATORS, l0_bb));
       set_immediate_dominator (CDI_DOMINATORS, l1_bb,
                               recompute_dominator (CDI_DOMINATORS, l1_bb));
+
+      struct loop *outer_loop = alloc_loop ();
+      outer_loop->header = l0_bb;
+      outer_loop->latch = l2_bb;
+      add_loop (outer_loop, l0_bb->loop_father);
+
+      struct loop *loop = alloc_loop ();
+      loop->header = l1_bb;
+      /* The loop may have multiple latches.  */
+      add_loop (loop, outer_loop);
     }
 }
 
@@ -4370,6 +4379,11 @@ expand_omp_for_static_nochunk (struct omp_region *region,
                           recompute_dominator (CDI_DOMINATORS, body_bb));
   set_immediate_dominator (CDI_DOMINATORS, fin_bb,
                           recompute_dominator (CDI_DOMINATORS, fin_bb));
+
+  struct loop *loop = alloc_loop ();
+  loop->header = body_bb;
+  loop->latch = cont_bb;
+  add_loop (loop, body_bb->loop_father);
 }
 
 
@@ -4671,6 +4685,16 @@ expand_omp_for_static_chunk (struct omp_region *region, struct omp_for_data *fd)
                           recompute_dominator (CDI_DOMINATORS, seq_start_bb));
   set_immediate_dominator (CDI_DOMINATORS, body_bb,
                           recompute_dominator (CDI_DOMINATORS, body_bb));
+
+  struct loop *trip_loop = alloc_loop ();
+  trip_loop->header = iter_part_bb;
+  trip_loop->latch = trip_update_bb;
+  add_loop (trip_loop, iter_part_bb->loop_father);
+
+  struct loop *loop = alloc_loop ();
+  loop->header = body_bb;
+  loop->latch = cont_bb;
+  add_loop (loop, trip_loop);
 }
 
 
@@ -4698,6 +4722,11 @@ expand_omp_for (struct omp_region *region)
       BRANCH_EDGE (region->cont)->flags &= ~EDGE_ABNORMAL;
       FALLTHRU_EDGE (region->cont)->flags &= ~EDGE_ABNORMAL;
     }
+  else
+    /* If there isnt a continue then this is a degerate case where
+       the introduction of abnormal edges during lowering will prevent
+       original loops from being detected.  Fix that up.  */
+    loops_state_set (LOOPS_NEED_FIXUP);
 
   if (fd.sched_kind == OMP_CLAUSE_SCHEDULE_STATIC
       && !fd.have_ordered
@@ -4914,7 +4943,7 @@ expand_omp_sections (struct omp_region *region)
   u = build_case_label (NULL, NULL, t);
   make_edge (l0_bb, default_bb, 0);
   if (current_loops)
-    add_bb_to_loop (default_bb, l0_bb->loop_father);
+    add_bb_to_loop (default_bb, current_loops->tree_root);
 
   stmt = gimple_build_switch (vmain, u, label_vec);
   gsi_insert_after (&switch_si, stmt, GSI_SAME_STMT);
@@ -5448,13 +5477,14 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb,
   /* Remove GIMPLE_OMP_ATOMIC_STORE.  */
   gsi_remove (&si, true);
 
+  struct loop *loop = alloc_loop ();
+  loop->header = loop_header;
+  loop->latch = loop_header;
+  add_loop (loop, loop_header->loop_father);
+
   if (gimple_in_ssa_p (cfun))
     update_ssa (TODO_update_ssa_no_phi);
 
-  /* ???  The above could use loop construction primitives.  */
-  if (current_loops)
-    loops_state_set (LOOPS_NEED_FIXUP);
-
   return true;
 }
 
index c75ae40ccab6a10f68c3e17238c3b81f77f247b0..25c01416e7779cf79993d7ccd4477c616d32de9b 100644 (file)
@@ -1,3 +1,8 @@
+2013-04-29  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/57089
+       * gfortran.dg/gomp/pr57089.f90: New testcase.
+
 2013-04-29  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * lib/target-supports.exp (vect_uintfloat_cvt): Enable for AArch64.
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr57089.f90 b/gcc/testsuite/gfortran.dg/gomp/pr57089.f90
new file mode 100644 (file)
index 0000000..ff742c6
--- /dev/null
@@ -0,0 +1,12 @@
+! PR middle-end/57089\r
+! { dg-do compile }\r
+! { dg-options "-O -fopenmp" }\r
+  SUBROUTINE T()\r
+    INTEGER            :: npoints, grad_deriv\r
+    SELECT CASE(grad_deriv)\r
+    CASE (0)\r
+       !$omp do\r
+       DO ii=1,npoints\r
+       END DO\r
+    END SELECT\r
+  END SUBROUTINE \r