@@ -1131,23 +1131,26 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
1131
1131
// We shouldn't try to use `L` anymore.
1132
1132
L = nullptr ;
1133
1133
} 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.
1135
1146
//
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
1151
1154
// remaining iterations just as it did in the original loop. Trying to also
1152
1155
// adjust the branch weights of the final unrolled iteration's latch (i.e.,
1153
1156
// the backedge for the unrolled loop as a whole) to reflect its new trip
0 commit comments