aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/Loads.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/Loads.cpp')
-rw-r--r--llvm/lib/Analysis/Loads.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 6fc81d787..78d0887 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -631,9 +631,13 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
if (!Val || !Len)
return nullptr;
- // TODO: Handle offsets.
- Value *Dst = MSI->getDest();
- if (!AreEquivalentAddressValues(Dst, Ptr))
+ // Handle offsets.
+ int64_t StoreOffset = 0, LoadOffset = 0;
+ const Value *StoreBase =
+ GetPointerBaseWithConstantOffset(MSI->getDest(), StoreOffset, DL);
+ const Value *LoadBase =
+ GetPointerBaseWithConstantOffset(Ptr, LoadOffset, DL);
+ if (StoreBase != LoadBase || LoadOffset < StoreOffset)
return nullptr;
if (IsLoadCSE)
@@ -645,7 +649,7 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
// Make sure the read bytes are contained in the memset.
uint64_t LoadSize = LoadTypeSize.getFixedValue();
- if ((Len->getValue() * 8).ult(LoadSize))
+ if ((Len->getValue() * 8).ult(LoadSize + (LoadOffset - StoreOffset) * 8))
return nullptr;
APInt Splat = LoadSize >= 8 ? APInt::getSplat(LoadSize, Val->getValue())
@@ -833,6 +837,10 @@ bool llvm::canReplacePointersInUseIfEqual(const Use &U, const Value *To,
if (!To->getType()->isPointerTy())
return true;
+ // Do not perform replacements in lifetime intrinsic arguments.
+ if (isa<LifetimeIntrinsic>(U.getUser()))
+ return false;
+
if (isPointerAlwaysReplaceable(&*U, To, DL))
return true;
return isPointerUseReplacable(U);