[PATCH] Fix incorrect loop exit edge probability [PR103270]

Xionghu Luo luoxhu@linux.ibm.com
Tue Nov 23 05:51:45 GMT 2021


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 ignores the EDGE_DFS_BACK edge when searching
extra exit edges to avoid unexpected predict_edge.

gcc/ChangeLog:

	PR middle-end/103270
	* predict.c (predict_extra_loop_exits): Ignore EDGE_DFS_BACK edge.

gcc/ChangeLog:

	PR middle-end/103270
	* predict.c (predict_extra_loop_exits): New.
---
 gcc/predict.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/predict.c b/gcc/predict.c
index 68b11135680..1ae8ccff72c 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -1910,6 +1910,10 @@ predict_extra_loop_exits (edge exit_edge)
 	continue;
       if ((check_value_one ^ integer_onep (val)) == 1)
 	continue;
+#if 0
+      if (e->flags & EDGE_DFS_BACK)
+	continue;
+#endif
       if (EDGE_COUNT (e->src->succs) != 1)
 	{
 	  predict_paths_leading_to_edge (e, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN);
-- 
2.25.1



More information about the Gcc-patches mailing list