@@ -453,13 +453,10 @@ LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
453
453
// See if the pointer expression is an AddRec like {base,+,1} on the current
454
454
// loop, which indicates a strided store. If we have something else, it's a
455
455
// random store we can't handle.
456
- const SCEVAddRecExpr *StoreEv =
457
- dyn_cast<SCEVAddRecExpr>(SE->getSCEV (StorePtr));
458
- if (!StoreEv || StoreEv->getLoop () != CurLoop || !StoreEv->isAffine ())
459
- return LegalStoreKind::None;
460
-
461
- // Check to see if we have a constant stride.
462
- if (!isa<SCEVConstant>(StoreEv->getOperand (1 )))
456
+ const SCEV *StoreEv = SE->getSCEV (StorePtr);
457
+ const SCEVConstant *Stride;
458
+ if (!match (StoreEv, m_scev_AffineAddRec (m_SCEV (), m_SCEVConstant (Stride))) ||
459
+ cast<SCEVAddRecExpr>(StoreEv)->getLoop () != CurLoop)
463
460
return LegalStoreKind::None;
464
461
465
462
// See if the store can be turned into a memset.
@@ -494,9 +491,9 @@ LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
494
491
if (HasMemcpy && !DisableLIRP::Memcpy) {
495
492
// Check to see if the stride matches the size of the store. If so, then we
496
493
// know that every byte is touched in the loop.
497
- APInt Stride = getStoreStride (StoreEv);
498
494
unsigned StoreSize = DL->getTypeStoreSize (SI->getValueOperand ()->getType ());
499
- if (StoreSize != Stride && StoreSize != -Stride)
495
+ APInt StrideAP = Stride->getAPInt ();
496
+ if (StoreSize != StrideAP && StoreSize != -StrideAP)
500
497
return LegalStoreKind::None;
501
498
502
499
// The store must be feeding a non-volatile load.
@@ -512,13 +509,12 @@ LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
512
509
// See if the pointer expression is an AddRec like {base,+,1} on the current
513
510
// loop, which indicates a strided load. If we have something else, it's a
514
511
// random load we can't handle.
515
- const SCEVAddRecExpr *LoadEv =
516
- dyn_cast<SCEVAddRecExpr>(SE->getSCEV (LI->getPointerOperand ()));
517
- if (!LoadEv || LoadEv->getLoop () != CurLoop || !LoadEv->isAffine ())
518
- return LegalStoreKind::None;
512
+ const SCEV *LoadEv = SE->getSCEV (LI->getPointerOperand ());
519
513
520
514
// The store and load must share the same stride.
521
- if (StoreEv->getOperand (1 ) != LoadEv->getOperand (1 ))
515
+ if (!match (LoadEv,
516
+ m_scev_AffineAddRec (m_SCEV (), m_scev_Specific (Stride))) ||
517
+ cast<SCEVAddRecExpr>(LoadEv)->getLoop () != CurLoop)
522
518
return LegalStoreKind::None;
523
519
524
520
// Success. This store can be converted into a memcpy.
@@ -854,15 +850,15 @@ bool LoopIdiomRecognize::processLoopMemSet(MemSetInst *MSI,
854
850
// See if the pointer expression is an AddRec like {base,+,1} on the current
855
851
// loop, which indicates a strided store. If we have something else, it's a
856
852
// random store we can't handle.
857
- const SCEVAddRecExpr *Ev = dyn_cast<SCEVAddRecExpr>(SE->getSCEV (Pointer));
858
- if (!Ev || Ev->getLoop () != CurLoop)
859
- return false ;
860
- if (!Ev->isAffine ()) {
853
+ const SCEV *Ev = SE->getSCEV (Pointer);
854
+ const SCEV *PointerStrideSCEV;
855
+ if (!match (Ev, m_scev_AffineAddRec (m_SCEV (), m_SCEV (PointerStrideSCEV)))) {
861
856
LLVM_DEBUG (dbgs () << " Pointer is not affine, abort\n " );
862
857
return false ;
863
858
}
859
+ if (cast<SCEVAddRecExpr>(Ev)->getLoop () != CurLoop)
860
+ return false ;
864
861
865
- const SCEV *PointerStrideSCEV = Ev->getOperand (1 );
866
862
const SCEV *MemsetSizeSCEV = SE->getSCEV (MSI->getLength ());
867
863
if (!PointerStrideSCEV || !MemsetSizeSCEV)
868
864
return false ;
@@ -877,7 +873,7 @@ bool LoopIdiomRecognize::processLoopMemSet(MemSetInst *MSI,
877
873
LLVM_DEBUG (dbgs () << " memset size is constant\n " );
878
874
uint64_t SizeInBytes = cast<ConstantInt>(MSI->getLength ())->getZExtValue ();
879
875
const APInt *Stride;
880
- if (!match (Ev-> getOperand ( 1 ) , m_scev_APInt (Stride)))
876
+ if (!match (PointerStrideSCEV , m_scev_APInt (Stride)))
881
877
return false ;
882
878
883
879
if (SizeInBytes != *Stride && SizeInBytes != -*Stride)
@@ -940,8 +936,9 @@ bool LoopIdiomRecognize::processLoopMemSet(MemSetInst *MSI,
940
936
SmallPtrSet<Instruction *, 1 > MSIs;
941
937
MSIs.insert (MSI);
942
938
return processLoopStridedStore (Pointer, SE->getSCEV (MSI->getLength ()),
943
- MSI->getDestAlign (), SplatValue, MSI, MSIs, Ev,
944
- BECount, IsNegStride, /* IsLoopMemset=*/ true );
939
+ MSI->getDestAlign (), SplatValue, MSI, MSIs,
940
+ cast<SCEVAddRecExpr>(Ev), BECount, IsNegStride,
941
+ /* IsLoopMemset=*/ true );
945
942
}
946
943
947
944
// / mayLoopAccessLocation - Return true if the specified loop might access the
@@ -1575,18 +1572,14 @@ class StrlenVerifier {
1575
1572
// See if the pointer expression is an AddRec with constant step a of form
1576
1573
// ({n,+,a}) where a is the width of the char type.
1577
1574
Value *IncPtr = LoopLoad->getPointerOperand ();
1578
- const SCEVAddRecExpr *LoadEv =
1579
- dyn_cast<SCEVAddRecExpr>(SE->getSCEV (IncPtr));
1580
- if (!LoadEv || LoadEv->getLoop () != CurLoop || !LoadEv->isAffine ())
1575
+ const SCEV *LoadEv = SE->getSCEV (IncPtr);
1576
+ const APInt *Step;
1577
+ if (!match (LoadEv,
1578
+ m_scev_AffineAddRec (m_SCEV (LoadBaseEv), m_scev_APInt (Step))))
1581
1579
return false ;
1582
- LoadBaseEv = LoadEv->getStart ();
1583
1580
1584
1581
LLVM_DEBUG (dbgs () << " pointer load scev: " << *LoadEv << " \n " );
1585
1582
1586
- const APInt *Step;
1587
- if (!match (LoadEv->getStepRecurrence (*SE), m_scev_APInt (Step)))
1588
- return false ;
1589
-
1590
1583
unsigned StepSize = Step->getZExtValue ();
1591
1584
1592
1585
// Verify that StepSize is consistent with platform char width.
0 commit comments