Skip to content

Commit 0b6a509

Browse files
Jan HubickaLiaoshihua
authored andcommitted
Fix profile update in duplicat_loop_body_to_header_edge for loops with 0 count_in
this patch makes duplicate_loop_body_to_header_edge to not drop profile counts to uninitialized when count_in is 0. This happens because profile_probability in 0 count is undefined. gcc/ChangeLog: * cfgloopmanip.cc (duplicate_loop_body_to_header_edge): Special case loops with 0 iteration count.
1 parent 16df9ae commit 0b6a509

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

gcc/cfgloopmanip.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,16 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e,
12961296
}
12971297
profile_probability prob_pass_wont_exit =
12981298
new_count_le.probability_in (count_in);
1299+
/* If profile count is 0, the probability will be uninitialized.
1300+
We can set probability to any initialized value to avoid
1301+
precision loss. If profile is sane, all counts will be 0 anyway. */
1302+
if (!count_in.nonzero_p ())
1303+
{
1304+
prob_pass_thru
1305+
= profile_probability::always ().apply_scale (1, 2);
1306+
prob_pass_wont_exit
1307+
= profile_probability::always ().apply_scale (1, 2);
1308+
}
12991309

13001310
scale_step = XNEWVEC (profile_probability, ndupl);
13011311

@@ -1306,7 +1316,9 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e,
13061316

13071317
/* Complete peeling is special as the probability of exit in last
13081318
copy becomes 1. */
1309-
if (flags & DLTHE_FLAG_COMPLETTE_PEEL)
1319+
if (!count_in.nonzero_p ())
1320+
;
1321+
else if (flags & DLTHE_FLAG_COMPLETTE_PEEL)
13101322
{
13111323
profile_count wanted_count = e->count ();
13121324

0 commit comments

Comments
 (0)