@@ -455,8 +455,8 @@ LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
455
455
// random store we can't handle.
456
456
const SCEV *StoreEv = SE->getSCEV (StorePtr);
457
457
const SCEVConstant *Stride;
458
- if (!match (StoreEv, m_scev_AffineAddRec (m_SCEV (), m_SCEVConstant (Stride))) ||
459
- cast<SCEVAddRecExpr>(StoreEv)-> getLoop () != CurLoop)
458
+ if (!match (StoreEv, m_scev_AffineAddRec (m_SCEV (), m_SCEVConstant (Stride),
459
+ m_SpecificLoop ( CurLoop))) )
460
460
return LegalStoreKind::None;
461
461
462
462
// See if the store can be turned into a memset.
@@ -512,9 +512,8 @@ LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
512
512
const SCEV *LoadEv = SE->getSCEV (LI->getPointerOperand ());
513
513
514
514
// The store and load must share the same stride.
515
- if (!match (LoadEv,
516
- m_scev_AffineAddRec (m_SCEV (), m_scev_Specific (Stride))) ||
517
- cast<SCEVAddRecExpr>(LoadEv)->getLoop () != CurLoop)
515
+ if (!match (LoadEv, m_scev_AffineAddRec (m_SCEV (), m_scev_Specific (Stride),
516
+ m_SpecificLoop (CurLoop))))
518
517
return LegalStoreKind::None;
519
518
520
519
// Success. This store can be converted into a memcpy.
@@ -787,25 +786,22 @@ bool LoopIdiomRecognize::processLoopMemCpy(MemCpyInst *MCI,
787
786
// See if the load and store pointer expressions are AddRec like {base,+,1} on
788
787
// the current loop, which indicates a strided load and store. If we have
789
788
// something else, it's a random load or store we can't handle.
790
- const SCEVAddRecExpr *StoreEv = dyn_cast<SCEVAddRecExpr>(SE->getSCEV (Dest));
791
- if (!StoreEv || StoreEv->getLoop () != CurLoop || !StoreEv->isAffine ())
792
- return false ;
793
- const SCEVAddRecExpr *LoadEv = dyn_cast<SCEVAddRecExpr>(SE->getSCEV (Source));
794
- if (!LoadEv || LoadEv->getLoop () != CurLoop || !LoadEv->isAffine ())
789
+ const SCEV *StoreEv = SE->getSCEV (Dest);
790
+ const SCEV *LoadEv = SE->getSCEV (Source);
791
+ const APInt *StoreStrideValue, *LoadStrideValue;
792
+ if (!match (StoreEv,
793
+ m_scev_AffineAddRec (m_SCEV (), m_scev_APInt (StoreStrideValue),
794
+ m_SpecificLoop (CurLoop))) ||
795
+ !match (LoadEv,
796
+ m_scev_AffineAddRec (m_SCEV (), m_scev_APInt (LoadStrideValue),
797
+ m_SpecificLoop (CurLoop))))
795
798
return false ;
796
799
797
800
// Reject memcpys that are so large that they overflow an unsigned.
798
801
uint64_t SizeInBytes = cast<ConstantInt>(MCI->getLength ())->getZExtValue ();
799
802
if ((SizeInBytes >> 32 ) != 0 )
800
803
return false ;
801
804
802
- // Check if the stride matches the size of the memcpy. If so, then we know
803
- // that every byte is touched in the loop.
804
- const APInt *StoreStrideValue, *LoadStrideValue;
805
- if (!match (StoreEv->getOperand (1 ), m_scev_APInt (StoreStrideValue)) ||
806
- !match (LoadEv->getOperand (1 ), m_scev_APInt (LoadStrideValue)))
807
- return false ;
808
-
809
805
// Huge stride value - give up
810
806
if (StoreStrideValue->getBitWidth () > 64 ||
811
807
LoadStrideValue->getBitWidth () > 64 )
@@ -830,8 +826,8 @@ bool LoopIdiomRecognize::processLoopMemCpy(MemCpyInst *MCI,
830
826
831
827
return processLoopStoreOfLoopLoad (
832
828
Dest, Source, SE->getConstant (Dest->getType (), SizeInBytes),
833
- MCI->getDestAlign (), MCI->getSourceAlign (), MCI, MCI, StoreEv, LoadEv,
834
- BECount);
829
+ MCI->getDestAlign (), MCI->getSourceAlign (), MCI, MCI,
830
+ cast<SCEVAddRecExpr>(StoreEv), cast<SCEVAddRecExpr>(LoadEv), BECount);
835
831
}
836
832
837
833
// / processLoopMemSet - See if this memset can be promoted to a large memset.
@@ -852,12 +848,11 @@ bool LoopIdiomRecognize::processLoopMemSet(MemSetInst *MSI,
852
848
// random store we can't handle.
853
849
const SCEV *Ev = SE->getSCEV (Pointer);
854
850
const SCEV *PointerStrideSCEV;
855
- if (!match (Ev, m_scev_AffineAddRec (m_SCEV (), m_SCEV (PointerStrideSCEV)))) {
851
+ if (!match (Ev, m_scev_AffineAddRec (m_SCEV (), m_SCEV (PointerStrideSCEV),
852
+ m_SpecificLoop (CurLoop)))) {
856
853
LLVM_DEBUG (dbgs () << " Pointer is not affine, abort\n " );
857
854
return false ;
858
855
}
859
- if (cast<SCEVAddRecExpr>(Ev)->getLoop () != CurLoop)
860
- return false ;
861
856
862
857
const SCEV *MemsetSizeSCEV = SE->getSCEV (MSI->getLength ());
863
858
0 commit comments