]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use sreal::nearest_int
authorJan Hubicka <jh@suse.cz>
Fri, 21 Jul 2023 14:50:49 +0000 (16:50 +0200)
committerJan Hubicka <jh@suse.cz>
Fri, 21 Jul 2023 14:51:46 +0000 (16:51 +0200)
Fix conversions from sreal to nearest integer.

gcc/ChangeLog:

* cfgloop.cc (get_estimated_loop_iterations): Use sreal::to_nearest_int
* cfgloopanal.cc (expected_loop_iterations_unbounded): Likewise.
* predict.cc (estimate_bb_frequencies): Likewise.
* profile.cc (branch_prob): Likewise.
* tree-ssa-loop-niter.cc (estimate_numbers_of_iterations): Likewise

gcc/cfgloop.cc
gcc/cfgloopanal.cc
gcc/predict.cc
gcc/profile.cc
gcc/tree-ssa-loop-niter.cc

index 9ca85e648a72f12175414b7874bd53c026d24f2b..6d46b5b0911cdbc0da912b167a55c3feb7371f37 100644 (file)
@@ -2012,7 +2012,7 @@ get_estimated_loop_iterations (class loop *loop, widest_int *nit)
       if (expected_loop_iterations_by_profile (loop, &snit, &reliable)
          && reliable)
        {
-         *nit = (snit + 0.5).to_int ();
+         *nit = snit.to_nearest_int ();
          return true;
        }
       return false;
index 2bf2eb06d6bda12dd2068a92fdc9c2c0f6dc19ff..c86a537f02458c4af3ac66dc49377d33b9179eed 100644 (file)
@@ -321,7 +321,7 @@ expected_loop_iterations_unbounded (const class loop *loop,
   sreal sreal_expected;
   if (expected_loop_iterations_by_profile
          (loop, &sreal_expected, read_profile_p))
-    expected = (sreal_expected + 0.5).to_int ();
+    expected = sreal_expected.to_nearest_int ();
   else
     expected = param_avg_loop_niter;
 
index 8f44f5b7db8cc1d509e862ce984e42f62067647e..6777e6cb9c5216b0f6e454b065adaa4fd9045a50 100644 (file)
@@ -4003,8 +4003,8 @@ estimate_bb_frequencies ()
                break;
              }
        }
-      tmp = tmp * freq_max + sreal (1, -1);
-      profile_count count = profile_count::from_gcov_type (tmp.to_int ());
+      tmp = tmp * freq_max;
+      profile_count count = profile_count::from_gcov_type (tmp.to_nearest_int ());
 
       /* If we have profile feedback in which this function was never
         executed, then preserve this info.  */
index 84d47b36d47e293eb7f1fffb3a99d134ba576fb5..fc59326a19ba17edc95b4e12fbe2cf679f62b3cf 100644 (file)
@@ -1553,7 +1553,7 @@ branch_prob (bool thunk)
            && expected_loop_iterations_by_profile (loop, &nit, &reliable)
            && reliable)
          {
-           widest_int bound = (nit + 0.5).to_int ();
+           widest_int bound = nit.to_nearest_int ();
            loop->any_estimate = false;
            record_niter_bound (loop, bound, true, false);
          }
index a8068014c5fc8edda253d7bdb01eb021b1af7708..705bcc009cdf298556dc82d3456939a3cc5fcab5 100644 (file)
@@ -4801,7 +4801,7 @@ estimate_numbers_of_iterations (class loop *loop)
       && expected_loop_iterations_by_profile (loop, &nit, &reliable)
       && reliable)
     {
-      bound = (nit + 0.5).to_int ();
+      bound = nit.to_nearest_int ();
       record_niter_bound (loop, bound, true, false);
     }