[PATCH] D25963: [LoopUnroll] Implement profile-based loop peeling

David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 13:09:02 PDT 2016

davidxl added inline comments.

Comment at: lib/Transforms/Utils/LoopUnrollPeel.cpp:101
+      // We no longer know anything about the branch probability.
+      LatchBR->setMetadata(LLVMContext::MD_prof, nullptr);
+    }
mkuper wrote:
> davidxl wrote:
> > Why? I think we should update the branch probability here -- it depends on the what iteration of the peeled clone. If peel count < average/estimated trip count, then each peeled iteration should be more biased towards fall through. If peel_count == est trip_count, then the last peel iteration should be biased toward exit.
> You're right, it's not that we don't know anything - but we don't know enough. I'm not sure how to attach a reasonable number to this, without knowing the distribution.
> Do you have any suggestions? The trivial option would be to assume an extremely narrow distribution (the loop always exits after exactly K iterations), but that would mean having an extreme bias for all of the branches, and I'm not sure that's wise.
A reasonable way to annotate the branch is like this.
Say the original trip count of the loop is N, then for the m th (from 0 to N-1) peeled iteration, the fall through probability is a decreasing function:

(N - m )/N

Add some fuzzing factor to avoid creating extremely biased branch prob:

for instance (N-m)*3/(4*N)


More information about the llvm-commits mailing list