]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix profile update in duplicat_loop_body_to_header_edge for loops with 0 count_in
authorJan Hubicka <jh@suse.cz>
Thu, 10 Aug 2023 17:01:43 +0000 (19:01 +0200)
committerJan Hubicka <jh@suse.cz>
Thu, 10 Aug 2023 17:01:43 +0000 (19:01 +0200)
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.

gcc/cfgloopmanip.cc

index b237ad4e8ac2db5a6baa93ec90a97864c57d1d2e..a2ed54a23bbc022b3f2e9de38f0d99b6c914d796 100644 (file)
@@ -1296,6 +1296,16 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e,
        }
       profile_probability prob_pass_wont_exit =
              new_count_le.probability_in (count_in);
+      /* If profile count is 0, the probability will be uninitialized.
+        We can set probability to any initialized value to avoid
+        precision loss.  If profile is sane, all counts will be 0 anyway.  */
+      if (!count_in.nonzero_p ())
+       {
+         prob_pass_thru
+                 = profile_probability::always ().apply_scale (1, 2);
+         prob_pass_wont_exit
+                 = profile_probability::always ().apply_scale (1, 2);
+       }
 
       scale_step = XNEWVEC (profile_probability, ndupl);
 
@@ -1306,7 +1316,9 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e,
 
       /* Complete peeling is special as the probability of exit in last
         copy becomes 1.  */
-      if (flags & DLTHE_FLAG_COMPLETTE_PEEL)
+      if (!count_in.nonzero_p ())
+       ;
+      else if (flags & DLTHE_FLAG_COMPLETTE_PEEL)
        {
          profile_count wanted_count = e->count ();