public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix the LOOP_BRANCH prediction
@ 2012-07-31  3:29 Dehao Chen
  2012-07-31  9:20 ` Richard Guenther
  0 siblings, 1 reply; 13+ messages in thread
From: Dehao Chen @ 2012-07-31  3:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jan Hubicka, David Li

Hi,

This patch fixed the problem when a LOOP_EXIT edge for the inner loop
happened to target at the LOOP_LATCH of the outer loop. As the outer
loop is processed first, the LOOP_BRANCH heuristic is honored
(first_match), thus the inner loop's trip count is 0. (The attached
unittest demonstrates this).

Bootstrapped and passed gcc regression test.

Is it ok for trunk?

Thanks,
Dehao

gcc/ChangeLog

2012-07-30  Dehao Chen  <dehao@google.com>

	* predict.c (predict_loops): Fix the prediction of LOOP_BRANCH.

gcc/testsuite/ChangeLog

2012-07-31  Dehao Chen  <dehao@google.com>

	* gcc.dg/predict-7.c: New test.

Index: gcc/testsuite/gcc.dg/predict-7.c
===================================================================
--- gcc/testsuite/gcc.dg/predict-7.c	(revision 0)
+++ gcc/testsuite/gcc.dg/predict-7.c	(revision 0)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+
+extern int global;
+
+int bar (int);
+
+void foo (int base)
+{
+  int i;
+  while (global < 10)
+    for (i = base; i < 10; i++)
+      bar (i);
+}
+
+/* { dg-final { scan-tree-dump-times "loop branch heuristics" 0
"profile_estimate"} } */
+/* { dg-final { cleanup-tree-dump "profile_estimate" } } */
Index: gcc/predict.c
===================================================================
--- gcc/predict.c	(revision 189835)
+++ gcc/predict.c	(working copy)
@@ -1404,7 +1404,7 @@

 	  /* Loop branch heuristics - predict an edge back to a
 	     loop's head as taken.  */
-	  if (bb == loop->latch)
+	  if (bb == loop->latch && bb->loop_father == loop)
 	    {
 	      e = find_edge (loop->latch, loop->header);
 	      if (e)

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-07-31 14:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-31  3:29 [PATCH] Fix the LOOP_BRANCH prediction Dehao Chen
2012-07-31  9:20 ` Richard Guenther
2012-07-31 10:24   ` Dehao Chen
2012-07-31 10:34     ` Jan Hubicka
2012-07-31 10:38     ` Richard Guenther
2012-07-31 10:43       ` Jan Hubicka
2012-07-31 10:46         ` Richard Guenther
2012-07-31 10:56           ` Richard Guenther
2012-07-31 11:00           ` Jan Hubicka
2012-07-31 12:39             ` Dehao Chen
2012-07-31 12:47               ` Jan Hubicka
2012-07-31 14:32                 ` Dehao Chen
2012-07-31 14:49                   ` Jan Hubicka

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).