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


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


	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)
       if ((check_value_one ^ integer_onep (val)) == 1)
+#if 0
+      if (e->flags & EDGE_DFS_BACK)
+	continue;
       if (EDGE_COUNT (e->src->succs) != 1)
 	  predict_paths_leading_to_edge (e, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN);

More information about the Gcc-patches mailing list