[llvm] r252926 - [LIR] Minor refactoring. NFCI.
Chad Rosier via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 12 11:09:16 PST 2015
Author: mcrosier
Date: Thu Nov 12 13:09:16 2015
New Revision: 252926
URL: http://llvm.org/viewvc/llvm-project?rev=252926&view=rev
Log:
[LIR] Minor refactoring. NFCI.
This change prevents uninteresting stores from being inserted into the list of
candidate stores for memset/memcpy conversion.
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp?rev=252926&r1=252925&r2=252926&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp Thu Nov 12 13:09:16 2015
@@ -118,6 +118,7 @@ private:
SmallVectorImpl<BasicBlock *> &ExitBlocks);
void collectStores(BasicBlock *BB);
+ bool isLegalStore(StoreInst *SI);
bool processLoopStore(StoreInst *SI, const SCEV *BECount);
bool processLoopMemSet(MemSetInst *MSI, const SCEV *BECount);
@@ -244,6 +245,42 @@ bool LoopIdiomRecognize::runOnCountableL
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 unsigned getStoreStride(const SCEVAddRecExpr *StoreEv) {
+ const SCEVConstant *ConstStride = cast<SCEVConstant>(StoreEv->getOperand(1));
+ return ConstStride->getValue()->getValue().getZExtValue();
+}
+
+bool LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
+ Value *StoredVal = SI->getValueOperand();
+ Value *StorePtr = SI->getPointerOperand();
+
+ // Reject stores that are so large that they overflow an unsigned.
+ uint64_t SizeInBits = DL->getTypeSizeInBits(StoredVal->getType());
+ if ((SizeInBits & 7) || (SizeInBits >> 32) != 0)
+ return false;
+
+ // See if the pointer expression is an AddRec like {base,+,1} on the current
+ // loop, which indicates a strided store. If we have something else, it's a
+ // random store we can't handle.
+ const SCEVAddRecExpr *StoreEv =
+ dyn_cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr));
+ if (!StoreEv || StoreEv->getLoop() != CurLoop || !StoreEv->isAffine())
+ return false;
+
+ // Check to see if we have a constant stride.
+ if (!isa<SCEVConstant>(StoreEv->getOperand(1)))
+ return false;
+
+ return true;
+}
+
void LoopIdiomRecognize::collectStores(BasicBlock *BB) {
StoreRefs.clear();
for (Instruction &I : *BB) {
@@ -255,6 +292,10 @@ void LoopIdiomRecognize::collectStores(B
if (!SI->isSimple())
continue;
+ // Make sure this is a strided store with a constant stride.
+ if (!isLegalStore(SI))
+ continue;
+
// Save the store locations.
StoreRefs.push_back(SI);
}
@@ -306,29 +347,11 @@ bool LoopIdiomRecognize::processLoopStor
Value *StoredVal = SI->getValueOperand();
Value *StorePtr = SI->getPointerOperand();
- // Reject stores that are so large that they overflow an unsigned.
- uint64_t SizeInBits = DL->getTypeSizeInBits(StoredVal->getType());
- if ((SizeInBits & 7) || (SizeInBits >> 32) != 0)
- return false;
-
- // See if the pointer expression is an AddRec like {base,+,1} on the current
- // loop, which indicates a strided store. If we have something else, it's a
- // random store we can't handle.
- const SCEVAddRecExpr *StoreEv =
- dyn_cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr));
- if (!StoreEv || StoreEv->getLoop() != CurLoop || !StoreEv->isAffine())
- return false;
-
// 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.
- unsigned StoreSize = (unsigned)SizeInBits >> 3;
-
- const SCEVConstant *ConstStride =
- dyn_cast<SCEVConstant>(StoreEv->getOperand(1));
- if (!ConstStride)
- return false;
-
- APInt Stride = ConstStride->getValue()->getValue();
+ const SCEVAddRecExpr *StoreEv = cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr));
+ unsigned Stride = getStoreStride(StoreEv);
+ unsigned StoreSize = getStoreSizeInBytes(SI, DL);
if (StoreSize != Stride && StoreSize != -Stride)
return false;
More information about the llvm-commits
mailing list