summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index 42da86a9ecf5..5d00fa56e888 100644
--- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -786,9 +786,9 @@ bool LoopIdiomRecognize::processLoopStores(SmallVectorImpl<StoreInst *> &SL,
Type *IntIdxTy = DL->getIndexType(StorePtr->getType());
const SCEV *StoreSizeSCEV = SE->getConstant(IntIdxTy, StoreSize);
if (processLoopStridedStore(StorePtr, StoreSizeSCEV,
- MaybeAlign(HeadStore->getAlignment()),
- StoredVal, HeadStore, AdjacentStores, StoreEv,
- BECount, IsNegStride)) {
+ MaybeAlign(HeadStore->getAlign()), StoredVal,
+ HeadStore, AdjacentStores, StoreEv, BECount,
+ IsNegStride)) {
TransformedStores.insert(AdjacentStores.begin(), AdjacentStores.end());
Changed = true;
}
@@ -967,12 +967,22 @@ bool LoopIdiomRecognize::processLoopMemSet(MemSetInst *MSI,
<< "\n");
if (PositiveStrideSCEV != MemsetSizeSCEV) {
- // TODO: folding can be done to the SCEVs
- // The folding is to fold expressions that is covered by the loop guard
- // at loop entry. After the folding, compare again and proceed
- // optimization if equal.
- LLVM_DEBUG(dbgs() << " SCEV don't match, abort\n");
- return false;
+ // If an expression is covered by the loop guard, compare again and
+ // proceed with optimization if equal.
+ const SCEV *FoldedPositiveStride =
+ SE->applyLoopGuards(PositiveStrideSCEV, CurLoop);
+ const SCEV *FoldedMemsetSize =
+ SE->applyLoopGuards(MemsetSizeSCEV, CurLoop);
+
+ LLVM_DEBUG(dbgs() << " Try to fold SCEV based on loop guard\n"
+ << " FoldedMemsetSize: " << *FoldedMemsetSize << "\n"
+ << " FoldedPositiveStride: " << *FoldedPositiveStride
+ << "\n");
+
+ if (FoldedPositiveStride != FoldedMemsetSize) {
+ LLVM_DEBUG(dbgs() << " SCEV don't match, abort\n");
+ return false;
+ }
}
}