public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6085] Fix incorrect loop exit edge probability [PR103270]
@ 2021-12-21  3:50 Xiong Hu Luo
  0 siblings, 0 replies; only message in thread
From: Xiong Hu Luo @ 2021-12-21  3:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:46bfe1b0e11c4797c5926e0754fae2848026376c

commit r12-6085-g46bfe1b0e11c4797c5926e0754fae2848026376c
Author: Xionghu Luo <luoxhu@linux.ibm.com>
Date:   Mon Dec 20 21:10:09 2021 -0600

    Fix incorrect loop exit edge probability [PR103270]
    
    r12-4526 cancelled jump thread path rotates loop. It exposes a issue in
    profile-estimate when predict_extra_loop_exits, outer loop's exit edge
    is marked as inner loop's extra loop exit and set with incorrect
    prediction, then a hot inner loop will become cold loop finally through
    optimizations, this patch add loop check when searching extra exit edges
    to avoid unexpected predict_edge from predict_paths_for_bb.
    
    Regression tested on P8LE.
    
    gcc/ChangeLog:
    
    2021-12-21  Xionghu Luo  <luoxhu@linux.ibm.com>
    
            PR middle-end/103270
            * predict.c (predict_extra_loop_exits): Add loop parameter.
            (predict_loops): Call with loop argument.
    
    gcc/testsuite/ChangeLog:
    
    2021-12-21  Xionghu Luo  <luoxhu@linux.ibm.com>
    
            PR middle-end/103270
            * gcc.dg/pr103270.c: New test.

Diff:
---
 gcc/predict.c                   | 10 ++++++----
 gcc/testsuite/gcc.dg/pr103270.c | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/gcc/predict.c b/gcc/predict.c
index 1a1da7e8360..1316ca88e20 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -1859,7 +1859,7 @@ predict_iv_comparison (class loop *loop, basic_block bb,
    exits to predict them using PRED_LOOP_EXTRA_EXIT.  */
 
 static void
-predict_extra_loop_exits (edge exit_edge)
+predict_extra_loop_exits (class loop *loop, edge exit_edge)
 {
   unsigned i;
   bool check_value_one;
@@ -1912,12 +1912,14 @@ predict_extra_loop_exits (edge exit_edge)
 	continue;
       if (EDGE_COUNT (e->src->succs) != 1)
 	{
-	  predict_paths_leading_to_edge (e, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN);
+	  predict_paths_leading_to_edge (e, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN,
+					 loop);
 	  continue;
 	}
 
       FOR_EACH_EDGE (e1, ei, e->src->preds)
-	predict_paths_leading_to_edge (e1, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN);
+	predict_paths_leading_to_edge (e1, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN,
+				       loop);
     }
 }
 
@@ -2008,7 +2010,7 @@ predict_loops (void)
 			 ex->src->index, ex->dest->index);
 	      continue;
 	    }
-	  predict_extra_loop_exits (ex);
+	  predict_extra_loop_exits (loop, ex);
 
 	  if (number_of_iterations_exit (loop, ex, &niter_desc, false, false))
 	    niter = niter_desc.niter;
diff --git a/gcc/testsuite/gcc.dg/pr103270.c b/gcc/testsuite/gcc.dg/pr103270.c
new file mode 100644
index 00000000000..819310e360e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103270.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+
+void test(int a, int* i)
+{
+  for (; a < 5; ++a)
+    {
+      int b = 0;
+      int c = 0;
+      for (; b != -11; b--)
+	for (int d = 0; d ==0; d++)
+	  {
+	    *i += c & a;
+	    c = b;
+	  }
+    }
+}
+
+/* { dg-final { scan-tree-dump-not "extra loop exit heuristics of edge\[^:\]*:" "profile_estimate"} } */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-21  3:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-21  3:50 [gcc r12-6085] Fix incorrect loop exit edge probability [PR103270] Xiong Hu Luo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).