@@ -575,19 +575,22 @@ split_loop (class loop *loop1)
575
575
stmts2 );
576
576
tree cond = build2 (guard_code , boolean_type_node , guard_init , border );
577
577
if (!initial_true )
578
- cond = fold_build1 (TRUTH_NOT_EXPR , boolean_type_node , cond );
578
+ cond = fold_build1 (TRUTH_NOT_EXPR , boolean_type_node , cond );
579
+
580
+ edge true_edge , false_edge ;
581
+ extract_true_false_edges_from_block (bbs [i ], & true_edge , & false_edge );
579
582
580
583
/* Now version the loop, placing loop2 after loop1 connecting
581
584
them, and fix up SSA form for that. */
582
585
initialize_original_copy_tables ();
583
586
basic_block cond_bb ;
584
587
585
588
class loop * loop2 = loop_version (loop1 , cond , & cond_bb ,
586
- profile_probability :: always () ,
587
- profile_probability :: always (),
588
- profile_probability ::always (),
589
- profile_probability ::always (),
590
- true);
589
+ true_edge -> probability ,
590
+ true_edge -> probability . invert (),
591
+ profile_probability ::always (),
592
+ profile_probability ::always (),
593
+ true);
591
594
gcc_assert (loop2 );
592
595
593
596
edge new_e = connect_loops (loop1 , loop2 );
@@ -607,6 +610,38 @@ split_loop (class loop *loop1)
607
610
tree guard_next = PHI_ARG_DEF_FROM_EDGE (phi , loop_latch_edge (loop1 ));
608
611
patch_loop_exit (loop1 , guard_stmt , guard_next , newend , initial_true );
609
612
613
+ update_ssa (TODO_update_ssa );
614
+
615
+ /* Proportion first loop's bb counts except those dominated by true
616
+ branch to avoid drop 1s down. */
617
+ basic_block * bbs1 , * bbs2 ;
618
+ bbs1 = get_loop_body (loop1 );
619
+ unsigned j ;
620
+ for (j = 0 ; j < loop1 -> num_nodes ; j ++ )
621
+ if (bbs1 [j ] == loop1 -> latch
622
+ || !dominated_by_p (CDI_DOMINATORS , bbs1 [j ], true_edge -> dest ))
623
+ bbs1 [j ]-> count
624
+ = bbs1 [j ]-> count .apply_probability (true_edge -> probability );
625
+ free (bbs1 );
626
+
627
+ /* Fix first loop's exit probability after scaling. */
628
+ edge exit_to_latch1 = single_pred_edge (loop1 -> latch );
629
+ exit_to_latch1 -> probability = exit_to_latch1 -> probability .apply_scale (
630
+ true_edge -> probability .to_reg_br_prob_base (), REG_BR_PROB_BASE );
631
+ single_exit (loop1 )-> probability
632
+ = exit_to_latch1 -> probability .invert ();
633
+
634
+ /* Proportion second loop's bb counts except those dominated by false
635
+ branch to avoid drop 1s down. */
636
+ basic_block bbi_copy = get_bb_copy (false_edge -> dest );
637
+ bbs2 = get_loop_body (loop2 );
638
+ for (j = 0 ; j < loop2 -> num_nodes ; j ++ )
639
+ if (bbs2 [j ] == loop2 -> latch
640
+ || !dominated_by_p (CDI_DOMINATORS , bbs2 [j ], bbi_copy ))
641
+ bbs2 [j ]-> count = bbs2 [j ]-> count .apply_probability (
642
+ true_edge -> probability .invert ());
643
+ free (bbs2 );
644
+
610
645
/* Finally patch out the two copies of the condition to be always
611
646
true/false (or opposite). */
612
647
gcond * force_true = as_a < gcond * > (last_stmt (bbs [i ]));
@@ -1486,8 +1521,8 @@ do_split_loop_on_cond (struct loop *loop1, edge invar_branch)
1486
1521
initialize_original_copy_tables ();
1487
1522
1488
1523
struct loop * loop2 = loop_version (loop1 , boolean_true_node , NULL ,
1489
- profile_probability :: always (),
1490
- profile_probability :: never () ,
1524
+ invar_branch -> probability . invert (),
1525
+ invar_branch -> probability ,
1491
1526
profile_probability ::always (),
1492
1527
profile_probability ::always (),
1493
1528
true);
@@ -1535,6 +1570,40 @@ do_split_loop_on_cond (struct loop *loop1, edge invar_branch)
1535
1570
between loop1 and loop2. */
1536
1571
connect_loop_phis (loop1 , loop2 , to_loop2 );
1537
1572
1573
+ update_ssa (TODO_update_ssa );
1574
+
1575
+ edge true_edge , false_edge , skip_edge1 , skip_edge2 ;
1576
+ extract_true_false_edges_from_block (cond_bb , & true_edge , & false_edge );
1577
+
1578
+ /* Proportion first loop's bb counts except those dominated by true
1579
+ branch to avoid drop 1s down. */
1580
+ skip_edge1 = true_invar ? false_edge : true_edge ;
1581
+ skip_edge2 = true_invar ? true_edge : false_edge ;
1582
+ basic_block * bbs1 , * bbs2 ;
1583
+ bbs1 = get_loop_body (loop1 );
1584
+ unsigned j ;
1585
+ for (j = 0 ; j < loop1 -> num_nodes ; j ++ )
1586
+ if (bbs1 [j ] == loop1 -> latch
1587
+ || !dominated_by_p (CDI_DOMINATORS , bbs1 [j ], skip_edge1 -> dest ))
1588
+ bbs1 [j ]-> count
1589
+ = bbs1 [j ]-> count .apply_probability (skip_edge1 -> probability );
1590
+ free (bbs1 );
1591
+
1592
+ /* Fix first loop's exit probability after scaling. */
1593
+ to_loop1 -> probability = invar_branch -> probability .invert ();
1594
+ to_loop2 -> probability = invar_branch -> probability ;
1595
+
1596
+ /* Proportion second loop's bb counts except those dominated by false
1597
+ branch to avoid drop 1s down. */
1598
+ basic_block bbi_copy = get_bb_copy (skip_edge2 -> dest );
1599
+ bbs2 = get_loop_body (loop2 );
1600
+ for (j = 0 ; j < loop2 -> num_nodes ; j ++ )
1601
+ if (bbs2 [j ] == loop2 -> latch
1602
+ || !dominated_by_p (CDI_DOMINATORS , bbs2 [j ], bbi_copy ))
1603
+ bbs2 [j ]-> count
1604
+ = bbs2 [j ]-> count .apply_probability (skip_edge2 -> probability );
1605
+ free (bbs2 );
1606
+
1538
1607
free_original_copy_tables ();
1539
1608
1540
1609
return true;
0 commit comments