Skip to content

Commit a4586bd

Browse files
committed
[Loads] Extract some checks into a lambda (NFC)
This makes it easier to add additional checks.
1 parent 311e4e3 commit a4586bd

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

llvm/lib/Analysis/Loads.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,26 @@ static bool isDereferenceableAndAlignedPointer(
9393
Visited, MaxDepth);
9494
}
9595

96-
bool CheckForNonNull, CheckForFreed;
97-
APInt KnownDerefBytes(Size.getBitWidth(),
98-
V->getPointerDereferenceableBytes(DL, CheckForNonNull,
99-
CheckForFreed));
100-
if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size) &&
101-
!CheckForFreed)
102-
if (!CheckForNonNull ||
103-
isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI))) {
104-
// As we recursed through GEPs to get here, we've incrementally checked
105-
// that each step advanced by a multiple of the alignment. If our base is
106-
// properly aligned, then the original offset accessed must also be.
107-
APInt Offset(DL.getTypeStoreSizeInBits(V->getType()), 0);
108-
return isAligned(V, Offset, Alignment, DL);
109-
}
96+
auto IsKnownDeref = [&]() {
97+
bool CheckForNonNull, CheckForFreed;
98+
APInt KnownDerefBytes(Size.getBitWidth(),
99+
V->getPointerDereferenceableBytes(DL, CheckForNonNull,
100+
CheckForFreed));
101+
if (!KnownDerefBytes.getBoolValue() || !KnownDerefBytes.uge(Size) ||
102+
CheckForFreed)
103+
return false;
104+
if (CheckForNonNull &&
105+
!isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI)))
106+
return false;
107+
return true;
108+
};
109+
if (IsKnownDeref()) {
110+
// As we recursed through GEPs to get here, we've incrementally checked
111+
// that each step advanced by a multiple of the alignment. If our base is
112+
// properly aligned, then the original offset accessed must also be.
113+
APInt Offset(DL.getTypeStoreSizeInBits(V->getType()), 0);
114+
return isAligned(V, Offset, Alignment, DL);
115+
}
110116

111117
/// TODO refactor this function to be able to search independently for
112118
/// Dereferencability and Alignment requirements.

0 commit comments

Comments
 (0)