Skip to content

Commit 3e55c80

Browse files
committed
Add comments
1 parent 2f73c04 commit 3e55c80

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llvm/lib/Transforms/Scalar/InferAlignment.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,25 @@ bool inferAlignment(Function &F, AssumptionCache &AC, DominatorTree &DT) {
7777
});
7878

7979
// Propagate alignment between loads and stores that originate from the
80-
// same base pointer
80+
// same base pointer.
8181
Changed |= tryToImproveAlign(
8282
DL, &I, [&](Value *PtrOp, Align LoadStoreAlign, Align PrefAlign) {
8383
APInt OffsetFromBase =
8484
APInt(DL.getIndexTypeSizeInBits(PtrOp->getType()), 0);
8585
PtrOp = PtrOp->stripAndAccumulateConstantOffsets(DL, OffsetFromBase,
8686
true);
87+
// Derive the base pointer alignment from the load/store alignment
88+
// and the offset from the base pointer.
8789
Align BasePointerAlign = commonAlignment(
8890
LoadStoreAlign, OffsetFromBase.getLimitedValue());
8991

9092
auto [It, Inserted] =
9193
BestBasePointerAligns.try_emplace(PtrOp, BasePointerAlign);
9294
if (!Inserted) {
95+
// If the stored base pointer alignment is better than the
96+
// base pointer alignment we derived, we may be able to use it
97+
// to improve the load/store alignment. If not, store the
98+
// improved base pointer alignment for future iterations.
9399
if (It->second > BasePointerAlign) {
94100
Align BetterLoadStoreAlign = commonAlignment(
95101
It->second, OffsetFromBase.getLimitedValue());

0 commit comments

Comments
 (0)