If a loop is cunrolled/vectorized, the AutoFDO computed trip count will be very small. This patch disallows overwritting of precomputed loop bound in AutoFDO mode.
Bootstrapped and passed regression test. Performance test on-going. OK for Google branches? Thanks, Dehao Index: tree-ssa-loop-niter.c =================================================================== --- tree-ssa-loop-niter.c (revision 206674) +++ tree-ssa-loop-niter.c (working copy) @@ -2520,7 +2520,8 @@ record_niter_bound (struct loop *loop, double_int } if (realistic && (!loop->any_estimate - || i_bound.ult (loop->nb_iterations_estimate))) + || (!flag_auto_profile && + i_bound.ult (loop->nb_iterations_estimate)))) { loop->any_estimate = true; loop->nb_iterations_estimate = i_bound;