summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2019-08-26 23:57:27 +0000
committerPhilip Reames <listmail@philipreames.com>2019-08-26 23:57:27 +0000
commit2f858c2e9198ce331fdb6a4f238b0697c8d016e9 (patch)
tree5865acac987fef03024dbf7a7fbcb7e9674bb848 /llvm/lib/Analysis
parent6137cecf87cc29e924d0bfb9f8f4bbe98b7c0f2b (diff)
downloadbcm5719-llvm-2f858c2e9198ce331fdb6a4f238b0697c8d016e9.tar.gz
bcm5719-llvm-2f858c2e9198ce331fdb6a4f238b0697c8d016e9.zip
Reorganize code and add a fixme to point out a bug in existing code [NFC]
llvm-svn: 369989
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/Loads.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 33db7fbe665..4de6b3e1744 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -41,13 +41,6 @@ static bool isAligned(const Value *Base, const APInt &Offset, unsigned Align,
return BaseAlign.uge(Alignment) && !(Offset & (Alignment-1));
}
-static bool isAligned(const Value *Base, unsigned Align, const DataLayout &DL) {
- Type *Ty = Base->getType();
- assert(Ty->isSized() && "must be sized");
- APInt Offset(DL.getTypeStoreSizeInBits(Ty), 0);
- return isAligned(Base, Offset, Align, DL);
-}
-
/// Test if V is always a pointer to allocated and suitably aligned memory for
/// a simple load or store.
static bool isDereferenceableAndAlignedPointer(
@@ -69,11 +62,16 @@ static bool isDereferenceableAndAlignedPointer(
bool CheckForNonNull = false;
APInt KnownDerefBytes(Size.getBitWidth(),
V->getPointerDereferenceableBytes(DL, CheckForNonNull));
- if (KnownDerefBytes.getBoolValue()) {
- if (KnownDerefBytes.uge(Size))
- if (!CheckForNonNull || isKnownNonZero(V, DL, 0, nullptr, CtxI, DT))
- return isAligned(V, Align, DL);
- }
+ if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size))
+ if (!CheckForNonNull || isKnownNonZero(V, DL, 0, nullptr, CtxI, DT)) {
+ // FIXME: We need to pass through original size/offset when we recurse,
+ // the result here is wrong for cases such as a 4 byte load, 2 bytes
+ // off a 8 byte aligned base.
+ Type *Ty = V->getType();
+ assert(Ty->isSized() && "must be sized");
+ APInt Offset(DL.getTypeStoreSizeInBits(Ty), 0);
+ return isAligned(V, Offset, Align, DL);
+ }
// For GEPs, determine if the indexing lands within the allocated object.
if (const GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
OpenPOWER on IntegriCloud