@@ -6662,12 +6662,13 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
6662
6662
struct function * saved_cfun = cfun ;
6663
6663
int * entry_flag , * exit_flag ;
6664
6664
unsigned * entry_prob , * exit_prob ;
6665
- unsigned i , num_entry_edges , num_exit_edges ;
6665
+ unsigned i , num_entry_edges , num_exit_edges , num_nodes ;
6666
6666
edge e ;
6667
6667
edge_iterator ei ;
6668
6668
htab_t new_label_map ;
6669
6669
struct pointer_map_t * vars_map , * eh_map ;
6670
6670
struct loop * loop = entry_bb -> loop_father ;
6671
+ struct loop * loop0 = get_loop (saved_cfun , 0 );
6671
6672
struct move_stmt_d d ;
6672
6673
6673
6674
/* If ENTRY does not strictly dominate EXIT, this cannot be an SESE
@@ -6760,16 +6761,29 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
6760
6761
set_loops_for_fn (dest_cfun , loops );
6761
6762
6762
6763
/* Move the outlined loop tree part. */
6764
+ num_nodes = bbs .length ();
6763
6765
FOR_EACH_VEC_ELT (bbs , i , bb )
6764
6766
{
6765
- if (bb -> loop_father -> header == bb
6766
- && loop_outer (bb -> loop_father ) == loop )
6767
+ if (bb -> loop_father -> header == bb )
6767
6768
{
6768
6769
struct loop * this_loop = bb -> loop_father ;
6769
- flow_loop_tree_node_remove (bb -> loop_father );
6770
- flow_loop_tree_node_add (get_loop (dest_cfun , 0 ), this_loop );
6771
- fixup_loop_arrays_after_move (saved_cfun , cfun , this_loop );
6770
+ struct loop * outer = loop_outer (this_loop );
6771
+ if (outer == loop
6772
+ /* If the SESE region contains some bbs ending with
6773
+ a noreturn call, those are considered to belong
6774
+ to the outermost loop in saved_cfun, rather than
6775
+ the entry_bb's loop_father. */
6776
+ || outer == loop0 )
6777
+ {
6778
+ if (outer != loop )
6779
+ num_nodes -= this_loop -> num_nodes ;
6780
+ flow_loop_tree_node_remove (bb -> loop_father );
6781
+ flow_loop_tree_node_add (get_loop (dest_cfun , 0 ), this_loop );
6782
+ fixup_loop_arrays_after_move (saved_cfun , cfun , this_loop );
6783
+ }
6772
6784
}
6785
+ else if (bb -> loop_father == loop0 && loop0 != loop )
6786
+ num_nodes -- ;
6773
6787
6774
6788
/* Remove loop exits from the outlined region. */
6775
6789
if (loops_for_fn (saved_cfun )-> exits )
@@ -6789,6 +6803,7 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
6789
6803
6790
6804
/* Setup a mapping to be used by move_block_to_fn. */
6791
6805
loop -> aux = current_loops -> tree_root ;
6806
+ loop0 -> aux = current_loops -> tree_root ;
6792
6807
6793
6808
pop_cfun ();
6794
6809
@@ -6817,11 +6832,13 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
6817
6832
}
6818
6833
6819
6834
loop -> aux = NULL ;
6835
+ loop0 -> aux = NULL ;
6820
6836
/* Loop sizes are no longer correct, fix them up. */
6821
- loop -> num_nodes -= bbs . length () ;
6837
+ loop -> num_nodes -= num_nodes ;
6822
6838
for (struct loop * outer = loop_outer (loop );
6823
6839
outer ; outer = loop_outer (outer ))
6824
- outer -> num_nodes -= bbs .length ();
6840
+ outer -> num_nodes -= num_nodes ;
6841
+ loop0 -> num_nodes -= bbs .length () - num_nodes ;
6825
6842
6826
6843
if (saved_cfun -> has_simduid_loops || saved_cfun -> has_force_vect_loops )
6827
6844
{
0 commit comments