diff options
| author | Chad Rosier <mcrosier@codeaurora.org> | 2015-11-19 18:22:21 +0000 |
|---|---|---|
| committer | Chad Rosier <mcrosier@codeaurora.org> | 2015-11-19 18:22:21 +0000 |
| commit | fddc01f39384712869409139e543a33c0b3bb850 (patch) | |
| tree | c0cd54a8cfbc21f60c1ae2bb329103896cb57f66 /llvm/lib/Transforms | |
| parent | 1d695a09ddd39d4163f9d08d250309865be7630f (diff) | |
| download | bcm5719-llvm-fddc01f39384712869409139e543a33c0b3bb850.tar.gz bcm5719-llvm-fddc01f39384712869409139e543a33c0b3bb850.zip | |
[LIR] Sink checks into function to enable future refactoring. NFC.
The purpose of this change is help delineate the memset and memcpy
optimizations with the overall goal of resolving PR25520.
llvm-svn: 253585
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index e3c84c6e71b..b385ca77dde 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -128,7 +128,6 @@ private: const SCEV *BECount, bool NegStride); bool processLoopStoreOfLoopLoad(StoreInst *SI, unsigned StoreSize, const SCEVAddRecExpr *StoreEv, - const SCEVAddRecExpr *LoadEv, const SCEV *BECount, bool NegStride); /// @} @@ -365,18 +364,7 @@ bool LoopIdiomRecognize::processLoopStore(StoreInst *SI, const SCEV *BECount) { // If the stored value is a strided load in the same loop with the same stride // this may be transformable into a memcpy. This kicks in for stuff like // for (i) A[i] = B[i]; - if (LoadInst *LI = dyn_cast<LoadInst>(StoredVal)) { - const SCEVAddRecExpr *LoadEv = - dyn_cast<SCEVAddRecExpr>(SE->getSCEV(LI->getPointerOperand())); - if (LoadEv && LoadEv->getLoop() == CurLoop && LoadEv->isAffine() && - StoreEv->getOperand(1) == LoadEv->getOperand(1) && LI->isSimple()) - if (processLoopStoreOfLoopLoad(SI, StoreSize, StoreEv, LoadEv, BECount, - NegStride)) - return true; - } - // errs() << "UNHANDLED strided store: " << *StoreEv << " - " << *SI << "\n"; - - return false; + return processLoopStoreOfLoopLoad(SI, StoreSize, StoreEv, BECount, NegStride); } /// processLoopMemSet - See if this memset can be promoted to a large memset. @@ -623,12 +611,26 @@ bool LoopIdiomRecognize::processLoopStridedStore( /// same-strided load. bool LoopIdiomRecognize::processLoopStoreOfLoopLoad( StoreInst *SI, unsigned StoreSize, const SCEVAddRecExpr *StoreEv, - const SCEVAddRecExpr *LoadEv, const SCEV *BECount, bool NegStride) { + const SCEV *BECount, bool NegStride) { // If we're not allowed to form memcpy, we fail. if (!TLI->has(LibFunc::memcpy)) return false; - LoadInst *LI = cast<LoadInst>(SI->getValueOperand()); + // The store must be feeding a non-volatile load. + LoadInst *LI = dyn_cast<LoadInst>(SI->getValueOperand()); + if (!LI || !LI->isSimple()) + return false; + + // See if the pointer expression is an AddRec like {base,+,1} on the current + // loop, which indicates a strided load. If we have something else, it's a + // random load we can't handle. + const SCEVAddRecExpr *LoadEv = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(LI->getPointerOperand())); + if (!LoadEv || LoadEv->getLoop() != CurLoop || !LoadEv->isAffine()) + return false; + + // The store and load must share the same stride. + if (StoreEv->getOperand(1) != LoadEv->getOperand(1)) + return false; // The trip count of the loop and the base pointer of the addrec SCEV is // guaranteed to be loop invariant, which means that it should dominate the |

