Skip to content

Commit edf46f3

Browse files
committed
[SCEV] Use const SCEV * explicitly in more places.
Use const SCEV * explicitly in more places to prepare for #91961. Split off as suggested.
1 parent 2fe3bbd commit edf46f3

14 files changed

+112
-104
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");
@@ -1084,7 +1084,7 @@ bool AccessAnalysis::createCheckForAccess(RuntimePointerChecking &RtCheck,
10841084
return false;
10851085

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

14451445
if (auto *OpAR = dyn_cast<SCEVAddRecExpr>(OpScev))
14461446
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
@@ -865,8 +865,8 @@ static void createMemSetLoop(Instruction *InsertBefore, Value *DstAddr,
865865
template <typename T>
866866
static bool canOverlap(MemTransferBase<T> *Memcpy, ScalarEvolution *SE) {
867867
if (SE) {
868-
auto *SrcSCEV = SE->getSCEV(Memcpy->getRawSource());
869-
auto *DestSCEV = SE->getSCEV(Memcpy->getRawDest());
868+
const SCEV *SrcSCEV = SE->getSCEV(Memcpy->getRawSource());
869+
const SCEV *DestSCEV = SE->getSCEV(Memcpy->getRawDest());
870870
if (SE->isKnownPredicateAt(CmpInst::ICMP_NE, SrcSCEV, DestSCEV, Memcpy))
871871
return false;
872872
}

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp

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

298298
bool SimplifyIndvar::eliminateSDiv(BinaryOperator *SDiv) {
299299
// Get the SCEVs for the ICmp operands.
300-
auto *N = SE->getSCEV(SDiv->getOperand(0));
301-
auto *D = SE->getSCEV(SDiv->getOperand(1));
300+
const SCEV *N = SE->getSCEV(SDiv->getOperand(0));
301+
const SCEV *D = SE->getSCEV(SDiv->getOperand(1));
302302

303303
// Simplify unnecessary loops away.
304304
const Loop *L = LI->getLoopFor(SDiv->getParent());
@@ -397,7 +397,7 @@ void SimplifyIndvar::simplifyIVRemainder(BinaryOperator *Rem,
397397
}
398398

399399
auto *T = Rem->getType();
400-
const auto *NLessOne = SE->getMinusSCEV(N, SE->getOne(T));
400+
const SCEV *NLessOne = SE->getMinusSCEV(N, SE->getOne(T));
401401
if (SE->isKnownPredicate(LT, NLessOne, D)) {
402402
replaceRemWithNumeratorOrZero(Rem);
403403
return;

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,15 @@ class SCEVAddRecForUniformityRewriter
507507
// Build a new AddRec by multiplying the step by StepMultiplier and
508508
// incrementing the start by Offset * step.
509509
Type *Ty = Expr->getType();
510-
auto *Step = Expr->getStepRecurrence(SE);
510+
const SCEV *Step = Expr->getStepRecurrence(SE);
511511
if (!SE.isLoopInvariant(Step, TheLoop)) {
512512
CannotAnalyze = true;
513513
return Expr;
514514
}
515-
auto *NewStep = SE.getMulExpr(Step, SE.getConstant(Ty, StepMultiplier));
516-
auto *ScaledOffset = SE.getMulExpr(Step, SE.getConstant(Ty, Offset));
517-
auto *NewStart = SE.getAddExpr(Expr->getStart(), ScaledOffset);
515+
const SCEV *NewStep =
516+
SE.getMulExpr(Step, SE.getConstant(Ty, StepMultiplier));
517+
const SCEV *ScaledOffset = SE.getMulExpr(Step, SE.getConstant(Ty, Offset));
518+
const SCEV *NewStart = SE.getAddExpr(Expr->getStart(), ScaledOffset);
518519
return SE.getAddRecExpr(NewStart, NewStep, TheLoop, SCEV::FlagAnyWrap);
519520
}
520521

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19062,10 +19062,10 @@ bool SLPVectorizerPass::vectorizeGEPIndices(BasicBlock *BB, BoUpSLP &R) {
1906219062
auto *GEPI = GEPList[I];
1906319063
if (!Candidates.count(GEPI))
1906419064
continue;
19065-
auto *SCEVI = SE->getSCEV(GEPList[I]);
19065+
const SCEV *SCEVI = SE->getSCEV(GEPList[I]);
1906619066
for (int J = I + 1; J < E && Candidates.size() > 1; ++J) {
1906719067
auto *GEPJ = GEPList[J];
19068-
auto *SCEVJ = SE->getSCEV(GEPList[J]);
19068+
const SCEV *SCEVJ = SE->getSCEV(GEPList[J]);
1906919069
if (isa<SCEVConstant>(SE->getMinusSCEV(SCEVI, SCEVJ))) {
1907019070
Candidates.remove(GEPI);
1907119071
Candidates.remove(GEPJ);

0 commit comments

Comments
 (0)