[PATCH] D158642: LoopUnrollRuntime: Add weights to all branches
Wenlei He via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 11 13:58:19 PDT 2023
wenlei accepted this revision.
wenlei added a comment.
lgtm, thanks!
================
Comment at: llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp:399-402
+ // Assign the maximum possible trip count as the back edge weight for
+ // the remainder loop if the original loop comes with a branch weight.
+ assert(Count > 1 && "unroll factor must be 2 or more");
+ uint64_t BackEdgeWeight = (Count - 1) * OrigExitWeight;
----------------
MatzeB wrote:
> MatzeB wrote:
> > wenlei wrote:
> > > I know this is just refactoring from `updateLatchBranchWeightsForRemainderLoop`, but I'm wondering if the assumption is reasonable? If we assume linear distribution for loop trip counts, then the average trip count for the remainder should be `Count / 2`, rather than `Count - 1`?
> > CC @hoy who originally added this (D83187).
> >
> > I think it would be `(Count / 2) - 1` for linear distribution. Guess I can change it as part of this patch...
> Given there is a pre-header to rule out zero-trip counts and this being a loop backedge, the average should be `(Count - 2) / 2`.
Makes sense. I didn't consider the fact that it's a backedge.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158642/new/
https://reviews.llvm.org/D158642
More information about the llvm-commits
mailing list