summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorJonas Paulsson <paulsson@linux.vnet.ibm.com>2017-11-28 14:44:32 +0000
committerJonas Paulsson <paulsson@linux.vnet.ibm.com>2017-11-28 14:44:32 +0000
commitf0ff20f1f01fb7c5323c1d89b5e0b19bec0e9e39 (patch)
treebe9db6d1dd1df7469862ffdf0461388f39a1f77a /llvm/lib/Transforms
parentb843dc26e4bc0dd5e3ee85f93194773cacc152ea (diff)
downloadbcm5719-llvm-f0ff20f1f01fb7c5323c1d89b5e0b19bec0e9e39.tar.gz
bcm5719-llvm-f0ff20f1f01fb7c5323c1d89b5e0b19bec0e9e39.zip
Use getStoreSize() in various places instead of 'BitSize >> 3'.
This is needed for cases when the memory access is not as big as the width of the data type. For instance, storing i1 (1 bit) would be done in a byte (8 bits). Using 'BitSize >> 3' (or '/ 8') would e.g. give the memory access of an i1 a size of 0, which for instance makes alias analysis return NoAlias even when it shouldn't. There are no tests as this was done as a follow-up to the bugfix for the case where this was discovered (r318824). This handles more similar cases. Review: Björn Petterson https://reviews.llvm.org/D40339 llvm-svn: 319173
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp15
1 files changed, 4 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index 7234b97f64d..3e331cddb4f 100644
--- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -334,13 +334,6 @@ bool LoopIdiomRecognize::runOnCountableLoop() {
return MadeChange;
}
-static unsigned getStoreSizeInBytes(StoreInst *SI, const DataLayout *DL) {
- uint64_t SizeInBits = DL->getTypeSizeInBits(SI->getValueOperand()->getType());
- assert(((SizeInBits & 7) || (SizeInBits >> 32) == 0) &&
- "Don't overflow unsigned.");
- return (unsigned)SizeInBits >> 3;
-}
-
static APInt getStoreStride(const SCEVAddRecExpr *StoreEv) {
const SCEVConstant *ConstStride = cast<SCEVConstant>(StoreEv->getOperand(1));
return ConstStride->getAPInt();
@@ -458,7 +451,7 @@ LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
// Check to see if the stride matches the size of the store. If so, then we
// know that every byte is touched in the loop.
APInt Stride = getStoreStride(StoreEv);
- unsigned StoreSize = getStoreSizeInBytes(SI, DL);
+ unsigned StoreSize = DL->getTypeStoreSize(SI->getValueOperand()->getType());
if (StoreSize != Stride && StoreSize != -Stride)
return LegalStoreKind::None;
@@ -597,7 +590,7 @@ bool LoopIdiomRecognize::processLoopStores(SmallVectorImpl<StoreInst *> &SL,
const SCEVAddRecExpr *FirstStoreEv =
cast<SCEVAddRecExpr>(SE->getSCEV(FirstStorePtr));
APInt FirstStride = getStoreStride(FirstStoreEv);
- unsigned FirstStoreSize = getStoreSizeInBytes(SL[i], DL);
+ unsigned FirstStoreSize = DL->getTypeStoreSize(SL[i]->getValueOperand()->getType());
// See if we can optimize just this store in isolation.
if (FirstStride == FirstStoreSize || -FirstStride == FirstStoreSize) {
@@ -690,7 +683,7 @@ bool LoopIdiomRecognize::processLoopStores(SmallVectorImpl<StoreInst *> &SL,
break;
AdjacentStores.insert(I);
- StoreSize += getStoreSizeInBytes(I, DL);
+ StoreSize += DL->getTypeStoreSize(I->getValueOperand()->getType());
// Move to the next value in the chain.
I = ConsecutiveChain[I];
}
@@ -964,7 +957,7 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(StoreInst *SI,
Value *StorePtr = SI->getPointerOperand();
const SCEVAddRecExpr *StoreEv = cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr));
APInt Stride = getStoreStride(StoreEv);
- unsigned StoreSize = getStoreSizeInBytes(SI, DL);
+ unsigned StoreSize = DL->getTypeStoreSize(SI->getValueOperand()->getType());
bool NegStride = StoreSize == -Stride;
// The store must be feeding a non-volatile load.
OpenPOWER on IntegriCloud