summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorArtur Pilipenko <apilipenko@azulsystems.com>2015-06-25 12:18:43 +0000
committerArtur Pilipenko <apilipenko@azulsystems.com>2015-06-25 12:18:43 +0000
commit0e21d54b516681edaed00ea7bd15dd0d1ee8bd4a (patch)
tree4ef472593011dd6990df4d545183b94694cde12c /llvm/lib
parent35a24ded0ae76ce3c2575b69a26461598465d74f (diff)
downloadbcm5719-llvm-0e21d54b516681edaed00ea7bd15dd0d1ee8bd4a.tar.gz
bcm5719-llvm-0e21d54b516681edaed00ea7bd15dd0d1ee8bd4a.zip
Take alignment into account in isSafeToLoadUnconditionally
Reviewed By: hfinkel Differential Revision: http://reviews.llvm.org/D10475 llvm-svn: 240636
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/Loads.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index aed3b04ebca..624c5a18d67 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -65,6 +65,12 @@ static bool AreEquivalentAddressValues(const Value *A, const Value *B) {
bool llvm::isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom,
unsigned Align) {
const DataLayout &DL = ScanFrom->getModule()->getDataLayout();
+
+ // Zero alignment means that the load has the ABI alignment for the target
+ if (Align == 0)
+ Align = DL.getABITypeAlignment(V->getType()->getPointerElementType());
+ assert(isPowerOf2_32(Align));
+
int64_t ByteOffset = 0;
Value *Base = V;
Base = GetPointerBaseWithConstantOffset(V, ByteOffset, DL);
@@ -102,7 +108,7 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom,
if (Align <= BaseAlign) {
// Check if the load is within the bounds of the underlying object.
if (ByteOffset + LoadSize <= DL.getTypeAllocSize(BaseType) &&
- (Align == 0 || (ByteOffset % Align) == 0))
+ ((ByteOffset % Align) == 0))
return true;
}
}
@@ -128,20 +134,28 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom,
return false;
Value *AccessedPtr;
- if (LoadInst *LI = dyn_cast<LoadInst>(BBI))
+ unsigned AccessedAlign;
+ if (LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
AccessedPtr = LI->getPointerOperand();
- else if (StoreInst *SI = dyn_cast<StoreInst>(BBI))
+ AccessedAlign = LI->getAlignment();
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {
AccessedPtr = SI->getPointerOperand();
- else
+ AccessedAlign = SI->getAlignment();
+ } else
+ continue;
+
+ Type *AccessedTy = AccessedPtr->getType()->getPointerElementType();
+ if (AccessedAlign == 0)
+ AccessedAlign = DL.getABITypeAlignment(AccessedTy);
+ if (AccessedAlign < Align)
continue;
// Handle trivial cases.
if (AccessedPtr == V)
return true;
- auto *AccessedTy = cast<PointerType>(AccessedPtr->getType());
if (AreEquivalentAddressValues(AccessedPtr->stripPointerCasts(), V) &&
- LoadSize <= DL.getTypeStoreSize(AccessedTy->getElementType()))
+ LoadSize <= DL.getTypeStoreSize(AccessedTy))
return true;
}
return false;
OpenPOWER on IntegriCloud