From: Chad Rosier Date: Thu, 19 Nov 2015 18:22:21 +0000 (+0000) Subject: [LIR] Sink checks into function to enable future refactoring. NFC. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bd71611f89f5fd4775e3f7b35e368f0241b0131d;p=oota-llvm.git [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253585 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index e3c84c6e71b..b385ca77dde 100644 --- a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/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(StoredVal)) { - const SCEVAddRecExpr *LoadEv = - dyn_cast(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(SI->getValueOperand()); + // The store must be feeding a non-volatile load. + LoadInst *LI = dyn_cast(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(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