Skip to content

Commit 2897e64

Browse files
committed
Improve some code comments
1 parent 967f8a1 commit 2897e64

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,23 +1131,26 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
11311131
// We shouldn't try to use `L` anymore.
11321132
L = nullptr;
11331133
} else if (OriginalTripCount) {
1134-
// Update metadata for the estimated trip count.
1134+
// Update metadata for the loop's branch weights and estimated trip count:
1135+
// - If ULO.Runtime, UnrollRuntimeLoopRemainder sets the guard branch
1136+
// weights, latch branch weights, and estimated trip count of the
1137+
// remainder loop it creates. It also sets the branch weights for the
1138+
// unrolled loop guard it creates. The branch weights for the unrolled
1139+
// loop latch are adjusted below. FIXME: Actually handle ULO.Runtime.
1140+
// - Otherwise, if unrolled loop iteration latches become unconditional,
1141+
// branch weights are adjusted above. FIXME: Actually handle such
1142+
// unconditional latches.
1143+
// - Otherwise, the original loop's branch weights are correct for the
1144+
// unrolled loop, so do not adjust them.
1145+
// - In all cases, the unrolled loop's estimated trip count is set below.
11351146
//
1136-
// If ULO.Runtime, UnrollRuntimeLoopRemainder handles branch weights for the
1137-
// remainder loop it creates, and the unrolled loop's branch weights are
1138-
// adjusted below. Otherwise, if unrolled loop iterations' latches become
1139-
// unconditional, branch weights are adjusted above. Otherwise, the
1140-
// original loop's branch weights are correct for the unrolled loop, so do
1141-
// not adjust them.
1142-
// FIXME: Actually handle such unconditional latches and ULO.Runtime.
1143-
//
1144-
// For example, consider what happens if the unroll count is 4 for a loop
1145-
// with an estimated trip count of 10 when we do not create a remainder loop
1146-
// and all iterations' latches remain conditional. Each unrolled
1147-
// iteration's latch still has the same probability of exiting the loop as
1148-
// it did when in the original loop, and thus it should still have the same
1149-
// branch weights. Each unrolled iteration's non-zero probability of
1150-
// exiting already appropriately reduces the probability of reaching the
1147+
// As an example of the last case, consider what happens if the unroll count
1148+
// is 4 for a loop with an estimated trip count of 10 when we do not create
1149+
// a remainder loop and all iterations' latches remain conditional. Each
1150+
// unrolled iteration's latch still has the same probability of exiting the
1151+
// loop as it did when in the original loop, and thus it should still have
1152+
// the same branch weights. Each unrolled iteration's non-zero probability
1153+
// of exiting already appropriately reduces the probability of reaching the
11511154
// remaining iterations just as it did in the original loop. Trying to also
11521155
// adjust the branch weights of the final unrolled iteration's latch (i.e.,
11531156
// the backedge for the unrolled loop as a whole) to reflect its new trip

0 commit comments

Comments
 (0)