Skip to content

Commit fc2064f

Browse files
committed
[SCEV] Use const SCEV * explicitly in more places.
1 parent 37ecd43 commit fc2064f

14 files changed

+109
-102
lines changed

llvm/lib/Analysis/Delinearization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct SCEVCollectAddRecMultiplies {
131131
if (auto *Mul = dyn_cast<SCEVMulExpr>(S)) {
132132
bool HasAddRec = false;
133133
SmallVector<const SCEV *, 0> Operands;
134-
for (const auto *Op : Mul->operands()) {
134+
for (const SCEV *Op : Mul->operands()) {
135135
const SCEVUnknown *Unknown = dyn_cast<SCEVUnknown>(Op);
136136
if (Unknown && !isa<CallInst>(Unknown->getValue())) {
137137
Operands.push_back(Op);

llvm/lib/Analysis/IVUsers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static bool isInteresting(const SCEV *S, const Instruction *I, const Loop *L,
7373
// An add is interesting if exactly one of its operands is interesting.
7474
if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
7575
bool AnyInterestingYet = false;
76-
for (const auto *Op : Add->operands())
76+
for (const SCEV *Op : Add->operands())
7777
if (isInteresting(Op, I, L, SE, LI)) {
7878
if (AnyInterestingYet)
7979
return false;
@@ -346,7 +346,7 @@ static const SCEVAddRecExpr *findAddRecForLoop(const SCEV *S, const Loop *L) {
346346
}
347347

348348
if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
349-
for (const auto *Op : Add->operands())
349+
for (const SCEV *Op : Add->operands())
350350
if (const SCEVAddRecExpr *AR = findAddRecForLoop(Op, L))
351351
return AR;
352352
return nullptr;

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ const SCEV *llvm::replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE,
171171
assert(isa<SCEVUnknown>(StrideSCEV) && "shouldn't be in map");
172172

173173
ScalarEvolution *SE = PSE.getSE();
174-
const auto *CT = SE->getOne(StrideSCEV->getType());
174+
const SCEV *CT = SE->getOne(StrideSCEV->getType());
175175
PSE.addPredicate(*SE->getEqualPredicate(StrideSCEV, CT));
176-
auto *Expr = PSE.getSCEV(Ptr);
176+
const SCEV *Expr = PSE.getSCEV(Ptr);
177177

178178
LLVM_DEBUG(dbgs() << "LAA: Replacing SCEV: " << *OrigSCEV
179179
<< " by: " << *Expr << "\n");
@@ -1087,7 +1087,7 @@ bool AccessAnalysis::createCheckForAccess(RuntimePointerChecking &RtCheck,
10871087
return false;
10881088

10891089
if (!isNoWrap(PSE, StridesMap, Ptr, AccessTy, TheLoop)) {
1090-
auto *Expr = PSE.getSCEV(Ptr);
1090+
const SCEV *Expr = PSE.getSCEV(Ptr);
10911091
if (!Assume || !isa<SCEVAddRecExpr>(Expr))
10921092
return false;
10931093
PSE.setNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW);
@@ -1443,7 +1443,7 @@ static bool isNoWrapAddRec(Value *Ptr, const SCEVAddRecExpr *AR,
14431443
// Assume constant for other the operand so that the AddRec can be
14441444
// easily found.
14451445
isa<ConstantInt>(OBO->getOperand(1))) {
1446-
auto *OpScev = PSE.getSCEV(OBO->getOperand(0));
1446+
const SCEV *OpScev = PSE.getSCEV(OBO->getOperand(0));
14471447

14481448
if (auto *OpAR = dyn_cast<SCEVAddRecExpr>(OpScev))
14491449
return OpAR->getLoop() == L && OpAR->getNoWrapFlags(SCEV::FlagNSW);

llvm/lib/Target/ARM/MVETailPredication.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ const SCEV *MVETailPredication::IsSafeActiveMask(IntrinsicInst *ActiveLaneMask,
205205
if (!L->makeLoopInvariant(ElemCount, Changed))
206206
return nullptr;
207207

208-
auto *EC= SE->getSCEV(ElemCount);
209-
auto *TC = SE->getSCEV(TripCount);
208+
const SCEV *EC = SE->getSCEV(ElemCount);
209+
const SCEV *TC = SE->getSCEV(TripCount);
210210
int VectorWidth =
211211
cast<FixedVectorType>(ActiveLaneMask->getType())->getNumElements();
212212
if (VectorWidth != 2 && VectorWidth != 4 && VectorWidth != 8 &&
@@ -228,7 +228,7 @@ const SCEV *MVETailPredication::IsSafeActiveMask(IntrinsicInst *ActiveLaneMask,
228228
// different counter. Using SCEV, we check that the induction is of the
229229
// form i = i + 4, where the increment must be equal to the VectorWidth.
230230
auto *IV = ActiveLaneMask->getOperand(0);
231-
auto *IVExpr = SE->getSCEV(IV);
231+
const SCEV *IVExpr = SE->getSCEV(IV);
232232
auto *AddExpr = dyn_cast<SCEVAddRecExpr>(IVExpr);
233233

234234
if (!AddExpr) {
@@ -291,14 +291,16 @@ const SCEV *MVETailPredication::IsSafeActiveMask(IntrinsicInst *ActiveLaneMask,
291291
//
292292
// which what we will be using here.
293293
//
294-
auto *VW = SE->getSCEV(ConstantInt::get(TripCount->getType(), VectorWidth));
294+
const SCEV *VW =
295+
SE->getSCEV(ConstantInt::get(TripCount->getType(), VectorWidth));
295296
// ElementCount + (VW-1):
296-
auto *Start = AddExpr->getStart();
297-
auto *ECPlusVWMinus1 = SE->getAddExpr(EC,
297+
const SCEV *Start = AddExpr->getStart();
298+
const SCEV *ECPlusVWMinus1 = SE->getAddExpr(
299+
EC,
298300
SE->getSCEV(ConstantInt::get(TripCount->getType(), VectorWidth - 1)));
299301

300302
// Ceil = ElementCount + (VW-1) / VW
301-
auto *Ceil = SE->getUDivExpr(ECPlusVWMinus1, VW);
303+
const SCEV *Ceil = SE->getUDivExpr(ECPlusVWMinus1, VW);
302304

303305
// Prevent unused variable warnings with TC
304306
(void)TC;

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ createReplacement(ICmpInst *ICmp, const Loop *L, BasicBlock *ExitingBB,
12871287
MaxIter = SE->getZeroExtendExpr(MaxIter, ARTy);
12881288
else if (SE->getTypeSizeInBits(ARTy) < SE->getTypeSizeInBits(MaxIterTy)) {
12891289
const SCEV *MinusOne = SE->getMinusOne(ARTy);
1290-
auto *MaxAllowedIter = SE->getZeroExtendExpr(MinusOne, MaxIterTy);
1290+
const SCEV *MaxAllowedIter = SE->getZeroExtendExpr(MinusOne, MaxIterTy);
12911291
if (SE->isKnownPredicateAt(ICmpInst::ICMP_ULE, MaxIter, MaxAllowedIter, BI))
12921292
MaxIter = SE->getTruncateExpr(MaxIter, ARTy);
12931293
}
@@ -1299,7 +1299,7 @@ createReplacement(ICmpInst *ICmp, const Loop *L, BasicBlock *ExitingBB,
12991299
// So we manually construct umin(a - 1, b - 1).
13001300
SmallVector<const SCEV *, 4> Elements;
13011301
if (auto *UMin = dyn_cast<SCEVUMinExpr>(MaxIter)) {
1302-
for (auto *Op : UMin->operands())
1302+
for (const SCEV *Op : UMin->operands())
13031303
Elements.push_back(SE->getMinusSCEV(Op, SE->getOne(Op->getType())));
13041304
MaxIter = SE->getUMinFromMismatchedTypes(Elements);
13051305
} else
@@ -1376,15 +1376,15 @@ static bool optimizeLoopExitWithUnknownExitCount(
13761376
for (auto *ICmp : LeafConditions) {
13771377
auto EL = SE->computeExitLimitFromCond(L, ICmp, Inverted,
13781378
/*ControlsExit*/ false);
1379-
auto *ExitMax = EL.SymbolicMaxNotTaken;
1379+
const SCEV *ExitMax = EL.SymbolicMaxNotTaken;
13801380
if (isa<SCEVCouldNotCompute>(ExitMax))
13811381
continue;
13821382
// They could be of different types (specifically this happens after
13831383
// IV widening).
13841384
auto *WiderType =
13851385
SE->getWiderType(ExitMax->getType(), MaxIter->getType());
1386-
auto *WideExitMax = SE->getNoopOrZeroExtend(ExitMax, WiderType);
1387-
auto *WideMaxIter = SE->getNoopOrZeroExtend(MaxIter, WiderType);
1386+
const SCEV *WideExitMax = SE->getNoopOrZeroExtend(ExitMax, WiderType);
1387+
const SCEV *WideMaxIter = SE->getNoopOrZeroExtend(MaxIter, WiderType);
13881388
if (WideExitMax == WideMaxIter)
13891389
ICmpsFailingOnLastIter.insert(ICmp);
13901390
}

llvm/lib/Transforms/Scalar/LoopDeletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ breakBackedgeIfNotTaken(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
404404
if (!L->getLoopLatch())
405405
return LoopDeletionResult::Unmodified;
406406

407-
auto *BTCMax = SE.getConstantMaxBackedgeTakenCount(L);
407+
const SCEV *BTCMax = SE.getConstantMaxBackedgeTakenCount(L);
408408
if (!BTCMax->isZero()) {
409-
auto *BTC = SE.getBackedgeTakenCount(L);
409+
const SCEV *BTC = SE.getBackedgeTakenCount(L);
410410
if (!BTC->isZero()) {
411411
if (!isa<SCEVCouldNotCompute>(BTC) && SE.isKnownNonZero(BTC))
412412
return LoopDeletionResult::Unmodified;

llvm/lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, SCEVExpander &Expander,
677677
LLVM_DEBUG(dbgs() << "Range check IV is not affine!\n");
678678
return std::nullopt;
679679
}
680-
auto *Step = RangeCheckIV->getStepRecurrence(*SE);
680+
const SCEV *Step = RangeCheckIV->getStepRecurrence(*SE);
681681
// We cannot just compare with latch IV step because the latch and range IVs
682682
// may have different types.
683683
if (!isSupportedStep(Step)) {
@@ -845,7 +845,7 @@ std::optional<LoopICmp> LoopPredication::parseLoopLatchICmp() {
845845
return std::nullopt;
846846
}
847847

848-
auto *Step = Result->IV->getStepRecurrence(*SE);
848+
const SCEV *Step = Result->IV->getStepRecurrence(*SE);
849849
if (!isSupportedStep(Step)) {
850850
LLVM_DEBUG(dbgs() << "Unsupported loop stride(" << *Step << ")!\n");
851851
return std::nullopt;

llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ static void createMemSetLoop(Instruction *InsertBefore, Value *DstAddr,
497497
template <typename T>
498498
static bool canOverlap(MemTransferBase<T> *Memcpy, ScalarEvolution *SE) {
499499
if (SE) {
500-
auto *SrcSCEV = SE->getSCEV(Memcpy->getRawSource());
501-
auto *DestSCEV = SE->getSCEV(Memcpy->getRawDest());
500+
const SCEV *SrcSCEV = SE->getSCEV(Memcpy->getRawSource());
501+
const SCEV *DestSCEV = SE->getSCEV(Memcpy->getRawDest());
502502
if (SE->isKnownPredicateAt(CmpInst::ICMP_NE, SrcSCEV, DestSCEV, Memcpy))
503503
return false;
504504
}

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ Value *SimplifyIndvar::foldIVUser(Instruction *UseInst, Instruction *IVOperand)
162162
D = ConstantInt::get(UseInst->getContext(),
163163
APInt::getOneBitSet(BitWidth, D->getZExtValue()));
164164
}
165-
const auto *LHS = SE->getSCEV(IVSrc);
166-
const auto *RHS = SE->getSCEV(D);
165+
const SCEV *LHS = SE->getSCEV(IVSrc);
166+
const SCEV *RHS = SE->getSCEV(D);
167167
FoldedExpr = SE->getUDivExpr(LHS, RHS);
168168
// We might have 'exact' flag set at this point which will no longer be
169169
// correct after we make the replacement.
@@ -292,8 +292,8 @@ void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp,
292292

293293
bool SimplifyIndvar::eliminateSDiv(BinaryOperator *SDiv) {
294294
// Get the SCEVs for the ICmp operands.
295-
auto *N = SE->getSCEV(SDiv->getOperand(0));
296-
auto *D = SE->getSCEV(SDiv->getOperand(1));
295+
const SCEV *N = SE->getSCEV(SDiv->getOperand(0));
296+
const SCEV *D = SE->getSCEV(SDiv->getOperand(1));
297297

298298
// Simplify unnecessary loops away.
299299
const Loop *L = LI->getLoopFor(SDiv->getParent());
@@ -389,7 +389,7 @@ void SimplifyIndvar::simplifyIVRemainder(BinaryOperator *Rem,
389389
}
390390

391391
auto *T = Rem->getType();
392-
const auto *NLessOne = SE->getMinusSCEV(N, SE->getOne(T));
392+
const SCEV *NLessOne = SE->getMinusSCEV(N, SE->getOne(T));
393393
if (SE->isKnownPredicate(LT, NLessOne, D)) {
394394
replaceRemWithNumeratorOrZero(Rem);
395395
return;

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,15 @@ class SCEVAddRecForUniformityRewriter
511511
// Build a new AddRec by multiplying the step by StepMultiplier and
512512
// incrementing the start by Offset * step.
513513
Type *Ty = Expr->getType();
514-
auto *Step = Expr->getStepRecurrence(SE);
514+
const SCEV *Step = Expr->getStepRecurrence(SE);
515515
if (!SE.isLoopInvariant(Step, TheLoop)) {
516516
CannotAnalyze = true;
517517
return Expr;
518518
}
519-
auto *NewStep = SE.getMulExpr(Step, SE.getConstant(Ty, StepMultiplier));
520-
auto *ScaledOffset = SE.getMulExpr(Step, SE.getConstant(Ty, Offset));
521-
auto *NewStart = SE.getAddExpr(Expr->getStart(), ScaledOffset);
519+
const SCEV *NewStep =
520+
SE.getMulExpr(Step, SE.getConstant(Ty, StepMultiplier));
521+
const SCEV *ScaledOffset = SE.getMulExpr(Step, SE.getConstant(Ty, Offset));
522+
const SCEV *NewStart = SE.getAddExpr(Expr->getStart(), ScaledOffset);
522523
return SE.getAddRecExpr(NewStart, NewStep, TheLoop, SCEV::FlagAnyWrap);
523524
}
524525

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18694,10 +18694,10 @@ bool SLPVectorizerPass::vectorizeGEPIndices(BasicBlock *BB, BoUpSLP &R) {
1869418694
auto *GEPI = GEPList[I];
1869518695
if (!Candidates.count(GEPI))
1869618696
continue;
18697-
auto *SCEVI = SE->getSCEV(GEPList[I]);
18697+
const SCEV *SCEVI = SE->getSCEV(GEPList[I]);
1869818698
for (int J = I + 1; J < E && Candidates.size() > 1; ++J) {
1869918699
auto *GEPJ = GEPList[J];
18700-
auto *SCEVJ = SE->getSCEV(GEPList[J]);
18700+
const SCEV *SCEVJ = SE->getSCEV(GEPList[J]);
1870118701
if (isa<SCEVConstant>(SE->getMinusSCEV(SCEVI, SCEVJ))) {
1870218702
Candidates.remove(GEPI);
1870318703
Candidates.remove(GEPJ);

0 commit comments

Comments
 (0)