[PATCH] D158642: LoopUnrollRuntime: Add weights to all branches
Matthias Braun via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 11 11:56:26 PDT 2023
MatzeB added inline comments.
================
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:
> 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`.
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