]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
peeling improvements
authorkubaneko <kubanek0ondrej@gmail.com>
Wed, 29 Mar 2023 13:40:21 +0000 (13:40 +0000)
committerkubaneko <kubanek0ondrej@gmail.com>
Wed, 29 Mar 2023 13:40:21 +0000 (13:40 +0000)
gcc/params.opt
gcc/tree-ssa-loop-ivcanon.cc

index c97b8584ec4ddc521eefdfa3ffccd05e68cd858e..a8f917e00b4aebc000b8162b1fe63bad2e6a1332 100644 (file)
@@ -875,7 +875,7 @@ Common Joined UInteger Var(param_prefetch_minimum_stride) Init(-1) Param Optimiz
 The minimum constant stride beyond which we should use prefetch hints for.
 
 -param=profile-histogram-size=
-Common Joined UInteger Var(param_profile_histogram_size) Init(69) IntegerRange(0, 255) Param Optimization
+Common Joined UInteger Var(param_profile_histogram_size) Init(15) IntegerRange(0, 255) Param Optimization
 Total size of the histogram counter for profile feedback.
 
 -param=profile-histogram-size-lin=
index 39dd6e58fdd96b7bd8b67621159482ea480a6649..347e143a4c70e285e659818a7a0fb22e12dce37a 100644 (file)
@@ -1035,7 +1035,7 @@ try_peel_loop (class loop *loop,
 
   /* Check if there is an estimate on the number of iterations.  */
   npeel = estimated_loop_iterations_int (loop);
-
+  auto_vec<int> good_peels;
   bool histogram_peeling=loop->counters!=NULL;
   if (histogram_peeling && loop->counters->sum!=0){
       gcov_type sum=loop->counters->sum;
@@ -1044,16 +1044,21 @@ try_peel_loop (class loop *loop,
       for (int i=0;i<param_profile_histogram_size_lin; i++){
           psum+=(*(loop->counters->hist))[i];
           // iteration has enough cumulated in partial sum and itself has at least 1 percent
-          if ((100*psum)/sum>=good_percentage && (*(loop->counters->hist))[i]*100/sum>0)
+          if ((100*psum)/sum>=good_percentage)
           {
-              int last=npeel;
-              npeel=i;
-            if ((maxiter >= 0 && maxiter <= npeel) || (npeel > param_max_peel_times - 1)) {
-               npeel=last;
+            good_peels.safe_push(i);
+            if ((maxiter >= 0 && maxiter <= good_peels.last()) ||
+                    (good_peels.last() > param_max_peel_times - 1)) {
+                good_peels.pop();
                break;
             }
-          good_percentage+=param_profile_histogram_peel_prcnt;
+            good_percentage=0;
+            psum=0;
           }
+          good_percentage+=param_profile_histogram_peel_prcnt;
+      }
+      if (!good_peels.is_empty()){
+          npeel=good_peels.pop();
       }
   }
 
@@ -1090,6 +1095,12 @@ try_peel_loop (class loop *loop,
   /* Check peeled loops size.  */
   tree_estimate_loop_size (loop, exit, NULL, &size,
                           param_max_peeled_insns);
+  while (!good_peels.is_empty() && 
+          (estimated_peeled_sequence_size (&size, (int) npeel) > param_max_peeled_insns))
+  {
+    npeel=good_peels.pop()++;
+  }
+
   if ((peeled_size = estimated_peeled_sequence_size (&size, (int) npeel))
       > param_max_peeled_insns)
     {