]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix division by zero in ipa-cp.cc:update_profiling_info
authorJan Hubicka <hubicka@ucw.cz>
Thu, 3 Jul 2025 09:56:28 +0000 (11:56 +0200)
committerJan Hubicka <hubicka@ucw.cz>
Thu, 3 Jul 2025 09:57:20 +0000 (11:57 +0200)
This ICE has triggered for me during autoprofiledbootstrap.  The
code already takes into care possible range, so I think in this case
we can just push to one side of it.

Bootstrapped/regtesed x86_64-linux, OK?

gcc/ChangeLog:

* ipa-cp.cc (update_profiling_info): Watch for division by zero.

gcc/ipa-cp.cc

index 901d4a5616e9d425028d624281b8d20a15d84810..480cf48786c7a40760e52119bceb7e0e55750eee 100644 (file)
@@ -4838,11 +4838,12 @@ update_profiling_info (struct cgraph_node *orig_node,
       profile_count unexp = orig_node_count - new_sum - orig_nonrec_call_count;
 
       int limit_den = 2 * (orig_nonrec_calls + new_nonrec_calls);
-      profile_count new_part
-       = MAX(MIN (unexp.apply_scale (new_sum,
-                                     new_sum + orig_nonrec_call_count),
-                  unexp.apply_scale (limit_den - 1, limit_den)),
-             unexp.apply_scale (new_nonrec_calls, limit_den));
+      profile_count new_part = unexp.apply_scale (limit_den - 1, limit_den);
+      profile_count den = new_sum + orig_nonrec_call_count;
+      if (den.nonzero_p ())
+       new_part = MIN (unexp.apply_scale (new_sum, den), new_part);
+      new_part = MAX (new_part,
+                     unexp.apply_scale (new_nonrec_calls, limit_den));
       if (dump_file)
        {
          fprintf (dump_file, "       Claiming ");