aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2024-08-03 20:10:00 +0100
committerFlorian Hahn <flo@fhahn.com>2024-08-03 20:10:01 +0100
commitedf46f365cf4e7caccd7459ac1a6912de5096857 (patch)
tree446f2cbe89f3287df73f9dafc31b6e8f796f8e98
parent2fe3bbdf6744949ee30830adc30ae9980fa8f682 (diff)
downloadllvm-edf46f365cf4e7caccd7459ac1a6912de5096857.zip
llvm-edf46f365cf4e7caccd7459ac1a6912de5096857.tar.gz
llvm-edf46f365cf4e7caccd7459ac1a6912de5096857.tar.bz2
[SCEV] Use const SCEV * explicitly in more places.
Use const SCEV * explicitly in more places to prepare for https://github.com/llvm/llvm-project/pull/91961. Split off as suggested.
-rw-r--r--llvm/lib/Analysis/Delinearization.cpp2
-rw-r--r--llvm/lib/Analysis/IVUsers.cpp4
-rw-r--r--llvm/lib/Analysis/LoopAccessAnalysis.cpp8
-rw-r--r--llvm/lib/Target/ARM/MVETailPredication.cpp16
-rw-r--r--llvm/lib/Transforms/Scalar/IndVarSimplify.cpp10
-rw-r--r--llvm/lib/Transforms/Scalar/LoopDeletion.cpp4
-rw-r--r--llvm/lib/Transforms/Scalar/LoopPredication.cpp4
-rw-r--r--llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp4
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyIndVar.cpp10
-rw-r--r--llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp9
-rw-r--r--llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp4
-rw-r--r--llvm/unittests/Analysis/ScalarEvolutionTest.cpp127
-rw-r--r--llvm/unittests/Transforms/Utils/LoopUtilsTest.cpp4
-rw-r--r--llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp10
14 files changed, 112 insertions, 104 deletions
diff --git a/llvm/lib/Analysis/Delinearization.cpp b/llvm/lib/Analysis/Delinearization.cpp
index 3cc83db..19845aa 100644
--- a/llvm/lib/Analysis/Delinearization.cpp
+++ b/llvm/lib/Analysis/Delinearization.cpp
@@ -131,7 +131,7 @@ struct SCEVCollectAddRecMultiplies {
if (auto *Mul = dyn_cast<SCEVMulExpr>(S)) {
bool HasAddRec = false;
SmallVector<const SCEV *, 0> Operands;
- for (const auto *Op : Mul->operands()) {
+ for (const SCEV *Op : Mul->operands()) {
const SCEVUnknown *Unknown = dyn_cast<SCEVUnknown>(Op);
if (Unknown && !isa<CallInst>(Unknown->getValue())) {
Operands.push_back(Op);
diff --git a/llvm/lib/Analysis/IVUsers.cpp b/llvm/lib/Analysis/IVUsers.cpp
index fc9f434..0880701 100644
--- a/llvm/lib/Analysis/IVUsers.cpp
+++ b/llvm/lib/Analysis/IVUsers.cpp
@@ -73,7 +73,7 @@ static bool isInteresting(const SCEV *S, const Instruction *I, const Loop *L,
// An add is interesting if exactly one of its operands is interesting.
if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
bool AnyInterestingYet = false;
- for (const auto *Op : Add->operands())
+ for (const SCEV *Op : Add->operands())
if (isInteresting(Op, I, L, SE, LI)) {
if (AnyInterestingYet)
return false;
@@ -346,7 +346,7 @@ static const SCEVAddRecExpr *findAddRecForLoop(const SCEV *S, const Loop *L) {
}
if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
- for (const auto *Op : Add->operands())
+ for (const SCEV *Op : Add->operands())
if (const SCEVAddRecExpr *AR = findAddRecForLoop(Op, L))
return AR;
return nullptr;
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index a2b124d..d67fd79 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -171,9 +171,9 @@ const SCEV *llvm::replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE,
assert(isa<SCEVUnknown>(StrideSCEV) && "shouldn't be in map");
ScalarEvolution *SE = PSE.getSE();
- const auto *CT = SE->getOne(StrideSCEV->getType());
+ const SCEV *CT = SE->getOne(StrideSCEV->getType());
PSE.addPredicate(*SE->getEqualPredicate(StrideSCEV, CT));
- auto *Expr = PSE.getSCEV(Ptr);
+ const SCEV *Expr = PSE.getSCEV(Ptr);
LLVM_DEBUG(dbgs() << "LAA: Replacing SCEV: " << *OrigSCEV
<< " by: " << *Expr << "\n");
@@ -1084,7 +1084,7 @@ bool AccessAnalysis::createCheckForAccess(RuntimePointerChecking &RtCheck,
return false;
if (!isNoWrap(PSE, StridesMap, Ptr, AccessTy, TheLoop)) {
- auto *Expr = PSE.getSCEV(Ptr);
+ const SCEV *Expr = PSE.getSCEV(Ptr);
if (!Assume || !isa<SCEVAddRecExpr>(Expr))
return false;
PSE.setNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW);
@@ -1440,7 +1440,7 @@ static bool isNoWrapAddRec(Value *Ptr, const SCEVAddRecExpr *AR,
// Assume constant for other the operand so that the AddRec can be
// easily found.
isa<ConstantInt>(OBO->getOperand(1))) {
- auto *OpScev = PSE.getSCEV(OBO->getOperand(0));
+ const SCEV *OpScev = PSE.getSCEV(OBO->getOperand(0));
if (auto *OpAR = dyn_cast<SCEVAddRecExpr>(OpScev))
return OpAR->getLoop() == L && OpAR->getNoWrapFlags(SCEV::FlagNSW);
diff --git a/llvm/lib/Target/ARM/MVETailPredication.cpp b/llvm/lib/Target/ARM/MVETailPredication.cpp
index c0fffe0..e554e4d 100644
--- a/llvm/lib/Target/ARM/MVETailPredication.cpp
+++ b/llvm/lib/Target/ARM/MVETailPredication.cpp
@@ -205,8 +205,8 @@ const SCEV *MVETailPredication::IsSafeActiveMask(IntrinsicInst *ActiveLaneMask,
if (!L->makeLoopInvariant(ElemCount, Changed))
return nullptr;
- auto *EC= SE->getSCEV(ElemCount);
- auto *TC = SE->getSCEV(TripCount);
+ const SCEV *EC = SE->getSCEV(ElemCount);
+ const SCEV *TC = SE->getSCEV(TripCount);
int VectorWidth =
cast<FixedVectorType>(ActiveLaneMask->getType())->getNumElements();
if (VectorWidth != 2 && VectorWidth != 4 && VectorWidth != 8 &&
@@ -228,7 +228,7 @@ const SCEV *MVETailPredication::IsSafeActiveMask(IntrinsicInst *ActiveLaneMask,
// different counter. Using SCEV, we check that the induction is of the
// form i = i + 4, where the increment must be equal to the VectorWidth.
auto *IV = ActiveLaneMask->getOperand(0);
- auto *IVExpr = SE->getSCEV(IV);
+ const SCEV *IVExpr = SE->getSCEV(IV);
auto *AddExpr = dyn_cast<SCEVAddRecExpr>(IVExpr);
if (!AddExpr) {
@@ -291,14 +291,16 @@ const SCEV *MVETailPredication::IsSafeActiveMask(IntrinsicInst *ActiveLaneMask,
//
// which what we will be using here.
//
- auto *VW = SE->getSCEV(ConstantInt::get(TripCount->getType(), VectorWidth));
+ const SCEV *VW =
+ SE->getSCEV(ConstantInt::get(TripCount->getType(), VectorWidth));
// ElementCount + (VW-1):
- auto *Start = AddExpr->getStart();
- auto *ECPlusVWMinus1 = SE->getAddExpr(EC,
+ const SCEV *Start = AddExpr->getStart();
+ const SCEV *ECPlusVWMinus1 = SE->getAddExpr(
+ EC,
SE->getSCEV(ConstantInt::get(TripCount->getType(), VectorWidth - 1)));
// Ceil = ElementCount + (VW-1) / VW
- auto *Ceil = SE->getUDivExpr(ECPlusVWMinus1, VW);
+ const SCEV *Ceil = SE->getUDivExpr(ECPlusVWMinus1, VW);
// Prevent unused variable warnings with TC
(void)TC;
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 5e2131b..3abf3aa 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1287,7 +1287,7 @@ createReplacement(ICmpInst *ICmp, const Loop *L, BasicBlock *ExitingBB,
MaxIter = SE->getZeroExtendExpr(MaxIter, ARTy);
else if (SE->getTypeSizeInBits(ARTy) < SE->getTypeSizeInBits(MaxIterTy)) {
const SCEV *MinusOne = SE->getMinusOne(ARTy);
- auto *MaxAllowedIter = SE->getZeroExtendExpr(MinusOne, MaxIterTy);
+ const SCEV *MaxAllowedIter = SE->getZeroExtendExpr(MinusOne, MaxIterTy);
if (SE->isKnownPredicateAt(ICmpInst::ICMP_ULE, MaxIter, MaxAllowedIter, BI))
MaxIter = SE->getTruncateExpr(MaxIter, ARTy);
}
@@ -1299,7 +1299,7 @@ createReplacement(ICmpInst *ICmp, const Loop *L, BasicBlock *ExitingBB,
// So we manually construct umin(a - 1, b - 1).
SmallVector<const SCEV *, 4> Elements;
if (auto *UMin = dyn_cast<SCEVUMinExpr>(MaxIter)) {
- for (auto *Op : UMin->operands())
+ for (const SCEV *Op : UMin->operands())
Elements.push_back(SE->getMinusSCEV(Op, SE->getOne(Op->getType())));
MaxIter = SE->getUMinFromMismatchedTypes(Elements);
} else
@@ -1376,15 +1376,15 @@ static bool optimizeLoopExitWithUnknownExitCount(
for (auto *ICmp : LeafConditions) {
auto EL = SE->computeExitLimitFromCond(L, ICmp, Inverted,
/*ControlsExit*/ false);
- auto *ExitMax = EL.SymbolicMaxNotTaken;
+ const SCEV *ExitMax = EL.SymbolicMaxNotTaken;
if (isa<SCEVCouldNotCompute>(ExitMax))
continue;
// They could be of different types (specifically this happens after
// IV widening).
auto *WiderType =
SE->getWiderType(ExitMax->getType(), MaxIter->getType());
- auto *WideExitMax = SE->getNoopOrZeroExtend(ExitMax, WiderType);
- auto *WideMaxIter = SE->getNoopOrZeroExtend(MaxIter, WiderType);
+ const SCEV *WideExitMax = SE->getNoopOrZeroExtend(ExitMax, WiderType);
+ const SCEV *WideMaxIter = SE->getNoopOrZeroExtend(MaxIter, WiderType);
if (WideExitMax == WideMaxIter)
ICmpsFailingOnLastIter.insert(ICmp);
}
diff --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
index b0b7ae6..e5355d2 100644
--- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -404,9 +404,9 @@ breakBackedgeIfNotTaken(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
if (!L->getLoopLatch())
return LoopDeletionResult::Unmodified;
- auto *BTCMax = SE.getConstantMaxBackedgeTakenCount(L);
+ const SCEV *BTCMax = SE.getConstantMaxBackedgeTakenCount(L);
if (!BTCMax->isZero()) {
- auto *BTC = SE.getBackedgeTakenCount(L);
+ const SCEV *BTC = SE.getBackedgeTakenCount(L);
if (!BTC->isZero()) {
if (!isa<SCEVCouldNotCompute>(BTC) && SE.isKnownNonZero(BTC))
return LoopDeletionResult::Unmodified;
diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
index 027dbb9..209b083 100644
--- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
@@ -677,7 +677,7 @@ LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, SCEVExpander &Expander,
LLVM_DEBUG(dbgs() << "Range check IV is not affine!\n");
return std::nullopt;
}
- auto *Step = RangeCheckIV->getStepRecurrence(*SE);
+ const SCEV *Step = RangeCheckIV->getStepRecurrence(*SE);
// We cannot just compare with latch IV step because the latch and range IVs
// may have different types.
if (!isSupportedStep(Step)) {
@@ -845,7 +845,7 @@ std::optional<LoopICmp> LoopPredication::parseLoopLatchICmp() {
return std::nullopt;
}
- auto *Step = Result->IV->getStepRecurrence(*SE);
+ const SCEV *Step = Result->IV->getStepRecurrence(*SE);
if (!isSupportedStep(Step)) {
LLVM_DEBUG(dbgs() << "Unsupported loop stride(" << *Step << ")!\n");
return std::nullopt;
diff --git a/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp b/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
index f0c7e31..ba62d75 100644
--- a/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
+++ b/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
@@ -865,8 +865,8 @@ static void createMemSetLoop(Instruction *InsertBefore, Value *DstAddr,
template <typename T>
static bool canOverlap(MemTransferBase<T> *Memcpy, ScalarEvolution *SE) {
if (SE) {
- auto *SrcSCEV = SE->getSCEV(Memcpy->getRawSource());
- auto *DestSCEV = SE->getSCEV(Memcpy->getRawDest());
+ const SCEV *SrcSCEV = SE->getSCEV(Memcpy->getRawSource());
+ const SCEV *DestSCEV = SE->getSCEV(Memcpy->getRawDest());
if (SE->isKnownPredicateAt(CmpInst::ICMP_NE, SrcSCEV, DestSCEV, Memcpy))
return false;
}
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 5bda7c5..8e3a14b 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -167,8 +167,8 @@ Value *SimplifyIndvar::foldIVUser(Instruction *UseInst, Instruction *IVOperand)
D = ConstantInt::get(UseInst->getContext(),
APInt::getOneBitSet(BitWidth, D->getZExtValue()));
}
- const auto *LHS = SE->getSCEV(IVSrc);
- const auto *RHS = SE->getSCEV(D);
+ const SCEV *LHS = SE->getSCEV(IVSrc);
+ const SCEV *RHS = SE->getSCEV(D);
FoldedExpr = SE->getUDivExpr(LHS, RHS);
// We might have 'exact' flag set at this point which will no longer be
// correct after we make the replacement.
@@ -297,8 +297,8 @@ void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp,
bool SimplifyIndvar::eliminateSDiv(BinaryOperator *SDiv) {
// Get the SCEVs for the ICmp operands.
- auto *N = SE->getSCEV(SDiv->getOperand(0));
- auto *D = SE->getSCEV(SDiv->getOperand(1));
+ const SCEV *N = SE->getSCEV(SDiv->getOperand(0));
+ const SCEV *D = SE->getSCEV(SDiv->getOperand(1));
// Simplify unnecessary loops away.
const Loop *L = LI->getLoopFor(SDiv->getParent());
@@ -397,7 +397,7 @@ void SimplifyIndvar::simplifyIVRemainder(BinaryOperator *Rem,
}
auto *T = Rem->getType();
- const auto *NLessOne = SE->getMinusSCEV(N, SE->getOne(T));
+ const SCEV *NLessOne = SE->getMinusSCEV(N, SE->getOne(T));
if (SE->isKnownPredicate(LT, NLessOne, D)) {
replaceRemWithNumeratorOrZero(Rem);
return;
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 5babb1d..465d0df 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -507,14 +507,15 @@ public:
// Build a new AddRec by multiplying the step by StepMultiplier and
// incrementing the start by Offset * step.
Type *Ty = Expr->getType();
- auto *Step = Expr->getStepRecurrence(SE);
+ const SCEV *Step = Expr->getStepRecurrence(SE);
if (!SE.isLoopInvariant(Step, TheLoop)) {
CannotAnalyze = true;
return Expr;
}
- auto *NewStep = SE.getMulExpr(Step, SE.getConstant(Ty, StepMultiplier));
- auto *ScaledOffset = SE.getMulExpr(Step, SE.getConstant(Ty, Offset));
- auto *NewStart = SE.getAddExpr(Expr->getStart(), ScaledOffset);
+ const SCEV *NewStep =
+ SE.getMulExpr(Step, SE.getConstant(Ty, StepMultiplier));
+ const SCEV *ScaledOffset = SE.getMulExpr(Step, SE.getConstant(Ty, Offset));
+ const SCEV *NewStart = SE.getAddExpr(Expr->getStart(), ScaledOffset);
return SE.getAddRecExpr(NewStart, NewStep, TheLoop, SCEV::FlagAnyWrap);
}
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 8d2ce6b..cd27342 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -19062,10 +19062,10 @@ bool SLPVectorizerPass::vectorizeGEPIndices(BasicBlock *BB, BoUpSLP &R) {
auto *GEPI = GEPList[I];
if (!Candidates.count(GEPI))
continue;
- auto *SCEVI = SE->getSCEV(GEPList[I]);
+ const SCEV *SCEVI = SE->getSCEV(GEPList[I]);
for (int J = I + 1; J < E && Candidates.size() > 1; ++J) {
auto *GEPJ = GEPList[J];
- auto *SCEVJ = SE->getSCEV(GEPList[J]);
+ const SCEV *SCEVJ = SE->getSCEV(GEPList[J]);
if (isa<SCEVConstant>(SE->getMinusSCEV(SCEVI, SCEVJ))) {
Candidates.remove(GEPI);
Candidates.remove(GEPJ);
diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
index 3802ae4..5e20e43 100644
--- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
+++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -141,9 +141,9 @@ TEST_F(ScalarEvolutionsTest, SimplifiedPHI) {
PN->addIncoming(Constant::getNullValue(Ty), EntryBB);
PN->addIncoming(UndefValue::get(Ty), LoopBB);
ScalarEvolution SE = buildSE(*F);
- auto *S1 = SE.getSCEV(PN);
- auto *S2 = SE.getSCEV(PN);
- auto *ZeroConst = SE.getConstant(Ty, 0);
+ const SCEV *S1 = SE.getSCEV(PN);
+ const SCEV *S2 = SE.getSCEV(PN);
+ const SCEV *ZeroConst = SE.getConstant(Ty, 0);
// At some point, only the first call to getSCEV returned the simplified
// SCEVConstant and later calls just returned a SCEVUnknown referencing the
@@ -238,9 +238,9 @@ TEST_F(ScalarEvolutionsTest, CommutativeExprOperandOrder) {
auto *IV0 = getInstructionByName(F, "iv0");
auto *IV0Inc = getInstructionByName(F, "iv0.inc");
- auto *FirstExprForIV0 = SE.getSCEV(IV0);
- auto *FirstExprForIV0Inc = SE.getSCEV(IV0Inc);
- auto *SecondExprForIV0 = SE.getSCEV(IV0);
+ const SCEV *FirstExprForIV0 = SE.getSCEV(IV0);
+ const SCEV *FirstExprForIV0Inc = SE.getSCEV(IV0Inc);
+ const SCEV *SecondExprForIV0 = SE.getSCEV(IV0);
EXPECT_TRUE(isa<SCEVAddRecExpr>(FirstExprForIV0));
EXPECT_TRUE(isa<SCEVAddRecExpr>(FirstExprForIV0Inc));
@@ -260,12 +260,12 @@ TEST_F(ScalarEvolutionsTest, CommutativeExprOperandOrder) {
SmallVector<const SCEV *, 3> Ops4 = {C, B, A};
SmallVector<const SCEV *, 3> Ops5 = {C, A, B};
- auto *Mul0 = SE.getMulExpr(Ops0);
- auto *Mul1 = SE.getMulExpr(Ops1);
- auto *Mul2 = SE.getMulExpr(Ops2);
- auto *Mul3 = SE.getMulExpr(Ops3);
- auto *Mul4 = SE.getMulExpr(Ops4);
- auto *Mul5 = SE.getMulExpr(Ops5);
+ const SCEV *Mul0 = SE.getMulExpr(Ops0);
+ const SCEV *Mul1 = SE.getMulExpr(Ops1);
+ const SCEV *Mul2 = SE.getMulExpr(Ops2);
+ const SCEV *Mul3 = SE.getMulExpr(Ops3);
+ const SCEV *Mul4 = SE.getMulExpr(Ops4);
+ const SCEV *Mul5 = SE.getMulExpr(Ops5);
EXPECT_EQ(Mul0, Mul1) << "Expected " << *Mul0 << " == " << *Mul1;
EXPECT_EQ(Mul1, Mul2) << "Expected " << *Mul1 << " == " << *Mul2;
@@ -383,8 +383,8 @@ TEST_F(ScalarEvolutionsTest, CompareValueComplexity) {
// CompareValueComplexity that is both fast and more accurate.
ScalarEvolution SE = buildSE(*F);
- auto *A = SE.getSCEV(MulA);
- auto *B = SE.getSCEV(MulB);
+ const SCEV *A = SE.getSCEV(MulA);
+ const SCEV *B = SE.getSCEV(MulB);
EXPECT_NE(A, B);
}
@@ -430,21 +430,21 @@ TEST_F(ScalarEvolutionsTest, SCEVAddExpr) {
EXPECT_EQ(AddWithNUW->getNumOperands(), 3u);
EXPECT_EQ(AddWithNUW->getNoWrapFlags(), SCEV::FlagNUW);
- auto *AddWithAnyWrap =
+ const SCEV *AddWithAnyWrap =
SE.getAddExpr(SE.getSCEV(A3), SE.getSCEV(A4), SCEV::FlagAnyWrap);
auto *AddWithAnyWrapNUW = cast<SCEVAddExpr>(
SE.getAddExpr(AddWithAnyWrap, SE.getSCEV(A5), SCEV::FlagNUW));
EXPECT_EQ(AddWithAnyWrapNUW->getNumOperands(), 3u);
EXPECT_EQ(AddWithAnyWrapNUW->getNoWrapFlags(), SCEV::FlagAnyWrap);
- auto *AddWithNSW = SE.getAddExpr(
+ const SCEV *AddWithNSW = SE.getAddExpr(
SE.getSCEV(A2), SE.getConstant(APInt(32, 99)), SCEV::FlagNSW);
auto *AddWithNSW_NUW = cast<SCEVAddExpr>(
SE.getAddExpr(AddWithNSW, SE.getSCEV(A5), SCEV::FlagNUW));
EXPECT_EQ(AddWithNSW_NUW->getNumOperands(), 3u);
EXPECT_EQ(AddWithNSW_NUW->getNoWrapFlags(), SCEV::FlagAnyWrap);
- auto *AddWithNSWNUW =
+ const SCEV *AddWithNSWNUW =
SE.getAddExpr(SE.getSCEV(A2), SE.getSCEV(A4),
ScalarEvolution::setFlags(SCEV::FlagNUW, SCEV::FlagNSW));
auto *AddWithNSWNUW_NUW = cast<SCEVAddExpr>(
@@ -780,8 +780,8 @@ TEST_F(ScalarEvolutionsTest, SCEVExitLimitForgetLoop) {
// The add recurrence {5,+,1} does not correspond to any PHI in the IR, and
// that is relevant to this test.
- auto *Five = SE.getConstant(APInt(/*numBits=*/64, 5));
- auto *AR =
+ const SCEV *Five = SE.getConstant(APInt(/*numBits=*/64, 5));
+ const SCEV *AR =
SE.getAddRecExpr(Five, SE.getOne(T_int64), Loop, SCEV::FlagAnyWrap);
const SCEV *ARAtLoopExit = SE.getSCEVAtScope(AR, nullptr);
EXPECT_FALSE(isa<SCEVCouldNotCompute>(ARAtLoopExit));
@@ -1019,19 +1019,19 @@ TEST_F(ScalarEvolutionsTest, SCEVFoldSumOfTruncs) {
ScalarEvolution SE = buildSE(*F);
auto *Arg = &*(F->arg_begin());
- const auto *ArgSCEV = SE.getSCEV(Arg);
+ const SCEV *ArgSCEV = SE.getSCEV(Arg);
// Build the SCEV
- const auto *A0 = SE.getNegativeSCEV(ArgSCEV);
- const auto *A1 = SE.getTruncateExpr(A0, Int32Ty);
- const auto *A = SE.getNegativeSCEV(A1);
+ const SCEV *A0 = SE.getNegativeSCEV(ArgSCEV);
+ const SCEV *A1 = SE.getTruncateExpr(A0, Int32Ty);
+ const SCEV *A = SE.getNegativeSCEV(A1);
- const auto *B0 = SE.getTruncateExpr(ArgSCEV, Int32Ty);
- const auto *B = SE.getNegativeSCEV(B0);
+ const SCEV *B0 = SE.getTruncateExpr(ArgSCEV, Int32Ty);
+ const SCEV *B = SE.getNegativeSCEV(B0);
- const auto *Expr = SE.getAddExpr(A, B);
+ const SCEV *Expr = SE.getAddExpr(A, B);
// Verify that the SCEV was folded to 0
- const auto *ZeroConst = SE.getConstant(Int32Ty, 0);
+ const SCEV *ZeroConst = SE.getConstant(Int32Ty, 0);
EXPECT_EQ(Expr, ZeroConst);
}
@@ -1108,7 +1108,7 @@ TEST_F(ScalarEvolutionsTest, SCEVLoopDecIntrinsic) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "foo", [&](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *ScevInc = SE.getSCEV(getInstructionByName(F, "inc"));
+ const SCEV *ScevInc = SE.getSCEV(getInstructionByName(F, "inc"));
EXPECT_TRUE(isa<SCEVAddRecExpr>(ScevInc));
});
}
@@ -1141,16 +1141,19 @@ TEST_F(ScalarEvolutionsTest, SCEVComputeConstantDifference) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *ScevV0 = SE.getSCEV(getInstructionByName(F, "v0")); // %pp
- auto *ScevV3 = SE.getSCEV(getInstructionByName(F, "v3")); // (3 + %pp)
- auto *ScevVX = SE.getSCEV(getInstructionByName(F, "vx")); // (%pp + %x)
+ const SCEV *ScevV0 = SE.getSCEV(getInstructionByName(F, "v0")); // %pp
+ const SCEV *ScevV3 = SE.getSCEV(getInstructionByName(F, "v3")); // (3 + %pp)
+ const SCEV *ScevVX =
+ SE.getSCEV(getInstructionByName(F, "vx")); // (%pp + %x)
// (%pp + %x + 3)
- auto *ScevVX3 = SE.getSCEV(getInstructionByName(F, "vx3"));
- auto *ScevIV = SE.getSCEV(getInstructionByName(F, "iv")); // {0,+,1}
- auto *ScevXA = SE.getSCEV(getInstructionByName(F, "xa")); // {%pp,+,1}
- auto *ScevYY = SE.getSCEV(getInstructionByName(F, "yy")); // {(3 + %pp),+,1}
- auto *ScevXB = SE.getSCEV(getInstructionByName(F, "xb")); // {%pp,+,1}
- auto *ScevIVNext = SE.getSCEV(getInstructionByName(F, "iv.next")); // {1,+,1}
+ const SCEV *ScevVX3 = SE.getSCEV(getInstructionByName(F, "vx3"));
+ const SCEV *ScevIV = SE.getSCEV(getInstructionByName(F, "iv")); // {0,+,1}
+ const SCEV *ScevXA = SE.getSCEV(getInstructionByName(F, "xa")); // {%pp,+,1}
+ const SCEV *ScevYY =
+ SE.getSCEV(getInstructionByName(F, "yy")); // {(3 + %pp),+,1}
+ const SCEV *ScevXB = SE.getSCEV(getInstructionByName(F, "xb")); // {%pp,+,1}
+ const SCEV *ScevIVNext =
+ SE.getSCEV(getInstructionByName(F, "iv.next")); // {1,+,1}
auto diff = [&SE](const SCEV *LHS, const SCEV *RHS) -> std::optional<int> {
auto ConstantDiffOrNone = computeConstantDifference(SE, LHS, RHS);
@@ -1203,16 +1206,17 @@ TEST_F(ScalarEvolutionsTest, SCEVrewriteUnknowns) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *ScevIV = SE.getSCEV(getInstructionByName(F, "iv")); // {0,+,1}
- auto *ScevI = SE.getSCEV(getArgByName(F, "i")); // {0,+,1}
+ const SCEV *ScevIV = SE.getSCEV(getInstructionByName(F, "iv")); // {0,+,1}
+ const SCEV *ScevI = SE.getSCEV(getArgByName(F, "i")); // {0,+,1}
ValueToSCEVMapTy RewriteMap;
RewriteMap[cast<SCEVUnknown>(ScevI)->getValue()] =
SE.getUMinExpr(ScevI, SE.getConstant(ScevI->getType(), 17));
- auto *WithUMin = SCEVParameterRewriter::rewrite(ScevIV, SE, RewriteMap);
+ const SCEV *WithUMin =
+ SCEVParameterRewriter::rewrite(ScevIV, SE, RewriteMap);
EXPECT_NE(WithUMin, ScevIV);
- auto *AR = dyn_cast<SCEVAddRecExpr>(WithUMin);
+ const auto *AR = dyn_cast<SCEVAddRecExpr>(WithUMin);
EXPECT_TRUE(AR);
EXPECT_EQ(AR->getStart(),
SE.getUMinExpr(ScevI, SE.getConstant(ScevI->getType(), 17)));
@@ -1233,9 +1237,9 @@ TEST_F(ScalarEvolutionsTest, SCEVAddNUW) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *X = SE.getSCEV(getArgByName(F, "x"));
- auto *One = SE.getOne(X->getType());
- auto *Sum = SE.getAddExpr(X, One, SCEV::FlagNUW);
+ const SCEV *X = SE.getSCEV(getArgByName(F, "x"));
+ const SCEV *One = SE.getOne(X->getType());
+ const SCEV *Sum = SE.getAddExpr(X, One, SCEV::FlagNUW);
EXPECT_TRUE(SE.isKnownPredicate(ICmpInst::ICMP_UGE, Sum, X));
EXPECT_TRUE(SE.isKnownPredicate(ICmpInst::ICMP_UGT, Sum, X));
});
@@ -1259,16 +1263,17 @@ TEST_F(ScalarEvolutionsTest, SCEVgetRanges) {
Err, C);
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *ScevIV = SE.getSCEV(getInstructionByName(F, "iv")); // {0,+,1}
- auto *ScevI = SE.getSCEV(getArgByName(F, "i"));
+ const SCEV *ScevIV = SE.getSCEV(getInstructionByName(F, "iv")); // {0,+,1}
+ const SCEV *ScevI = SE.getSCEV(getArgByName(F, "i"));
EXPECT_EQ(SE.getUnsignedRange(ScevIV).getLower(), 0);
EXPECT_EQ(SE.getUnsignedRange(ScevIV).getUpper(), 16);
- auto *Add = SE.getAddExpr(ScevI, ScevIV);
+ const SCEV *Add = SE.getAddExpr(ScevI, ScevIV);
ValueToSCEVMapTy RewriteMap;
RewriteMap[cast<SCEVUnknown>(ScevI)->getValue()] =
SE.getUMinExpr(ScevI, SE.getConstant(ScevI->getType(), 17));
- auto *AddWithUMin = SCEVParameterRewriter::rewrite(Add, SE, RewriteMap);
+ const SCEV *AddWithUMin =
+ SCEVParameterRewriter::rewrite(Add, SE, RewriteMap);
EXPECT_EQ(SE.getUnsignedRange(AddWithUMin).getLower(), 0);
EXPECT_EQ(SE.getUnsignedRange(AddWithUMin).getUpper(), 33);
});
@@ -1296,7 +1301,7 @@ TEST_F(ScalarEvolutionsTest, SCEVgetExitLimitForGuardedLoop) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *ScevIV = SE.getSCEV(getInstructionByName(F, "iv")); // {0,+,1}
+ const SCEV *ScevIV = SE.getSCEV(getInstructionByName(F, "iv")); // {0,+,1}
const Loop *L = cast<SCEVAddRecExpr>(ScevIV)->getLoop();
const SCEV *BTC = SE.getBackedgeTakenCount(L);
@@ -1331,7 +1336,7 @@ TEST_F(ScalarEvolutionsTest, ImpliedViaAddRecStart) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *X = SE.getSCEV(getInstructionByName(F, "x"));
+ const SCEV *X = SE.getSCEV(getInstructionByName(F, "x"));
auto *Context = getInstructionByName(F, "iv.next");
EXPECT_TRUE(SE.isKnownPredicateAt(ICmpInst::ICMP_NE, X,
SE.getZero(X->getType()), Context));
@@ -1360,8 +1365,8 @@ TEST_F(ScalarEvolutionsTest, UnsignedIsImpliedViaOperations) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *X = SE.getSCEV(getInstructionByName(F, "x"));
- auto *Y = SE.getSCEV(getInstructionByName(F, "y"));
+ const SCEV *X = SE.getSCEV(getInstructionByName(F, "x"));
+ const SCEV *Y = SE.getSCEV(getInstructionByName(F, "y"));
auto *Guarded = getInstructionByName(F, "y")->getParent();
ASSERT_TRUE(Guarded);
EXPECT_TRUE(
@@ -1403,8 +1408,8 @@ TEST_F(ScalarEvolutionsTest, ProveImplicationViaNarrowing) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *IV = SE.getSCEV(getInstructionByName(F, "iv"));
- auto *Zero = SE.getZero(IV->getType());
+ const SCEV *IV = SE.getSCEV(getInstructionByName(F, "iv"));
+ const SCEV *Zero = SE.getZero(IV->getType());
auto *Backedge = getInstructionByName(F, "iv.next")->getParent();
ASSERT_TRUE(Backedge);
(void)IV;
@@ -1531,8 +1536,8 @@ TEST_F(ScalarEvolutionsTest, SCEVUDivFloorCeiling) {
using namespace llvm::APIntOps;
APInt FloorInt = RoundingUDiv(NInt, DInt, APInt::Rounding::DOWN);
APInt CeilingInt = RoundingUDiv(NInt, DInt, APInt::Rounding::UP);
- auto *NS = SE.getConstant(NInt);
- auto *DS = SE.getConstant(DInt);
+ const SCEV *NS = SE.getConstant(NInt);
+ const SCEV *DS = SE.getConstant(DInt);
auto *FloorS = cast<SCEVConstant>(SE.getUDivExpr(NS, DS));
auto *CeilingS = cast<SCEVConstant>(SE.getUDivCeilSCEV(NS, DS));
ASSERT_TRUE(FloorS->getAPInt() == FloorInt);
@@ -1584,13 +1589,13 @@ TEST_F(ScalarEvolutionsTest, ApplyLoopGuards) {
ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
runWithSE(*M, "test", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
- auto *TCScev = SE.getSCEV(getArgByName(F, "num"));
- auto *ApplyLoopGuardsTC = SE.applyLoopGuards(TCScev, *LI.begin());
+ const SCEV *TCScev = SE.getSCEV(getArgByName(F, "num"));
+ const SCEV *ApplyLoopGuardsTC = SE.applyLoopGuards(TCScev, *LI.begin());
// Assert that the new TC is (4 * ((4 umax %num) /u 4))
APInt Four(32, 4);
- auto *Constant4 = SE.getConstant(Four);
- auto *Max = SE.getUMaxExpr(TCScev, Constant4);
- auto *Mul = SE.getMulExpr(SE.getUDivExpr(Max, Constant4), Constant4);
+ const SCEV *Constant4 = SE.getConstant(Four);
+ const SCEV *Max = SE.getUMaxExpr(TCScev, Constant4);
+ const SCEV *Mul = SE.getMulExpr(SE.getUDivExpr(Max, Constant4), Constant4);
ASSERT_TRUE(Mul == ApplyLoopGuardsTC);
});
}
diff --git a/llvm/unittests/Transforms/Utils/LoopUtilsTest.cpp b/llvm/unittests/Transforms/Utils/LoopUtilsTest.cpp
index 2b11aad..cd47171 100644
--- a/llvm/unittests/Transforms/Utils/LoopUtilsTest.cpp
+++ b/llvm/unittests/Transforms/Utils/LoopUtilsTest.cpp
@@ -114,7 +114,7 @@ TEST(LoopUtils, IsKnownPositiveInLoopTest) {
Loop *L = *LI.begin();
assert(L && L->getName() == "loop" && "Expecting loop 'loop'");
auto *Arg = F.getArg(0);
- auto *ArgSCEV = SE.getSCEV(Arg);
+ const SCEV *ArgSCEV = SE.getSCEV(Arg);
EXPECT_EQ(isKnownPositiveInLoop(ArgSCEV, L, SE), true);
});
}
@@ -138,7 +138,7 @@ TEST(LoopUtils, IsKnownNonPositiveInLoopTest) {
Loop *L = *LI.begin();
assert(L && L->getName() == "loop" && "Expecting loop 'loop'");
auto *Arg = F.getArg(0);
- auto *ArgSCEV = SE.getSCEV(Arg);
+ const SCEV *ArgSCEV = SE.getSCEV(Arg);
EXPECT_EQ(isKnownNonPositiveInLoop(ArgSCEV, L, SE), true);
});
}
diff --git a/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp b/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
index 9e80c6d..c4560cb 100644
--- a/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
+++ b/llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
@@ -117,7 +117,7 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandPtrTypeSCEV) {
CastInst::CreateBitOrPointerCast(Sel, I32PtrTy, "bitcast2", Br);
ScalarEvolution SE = buildSE(*F);
- auto *S = SE.getSCEV(CastB);
+ const SCEV *S = SE.getSCEV(CastB);
EXPECT_TRUE(isa<SCEVUnknown>(S));
}
@@ -185,7 +185,7 @@ TEST_F(ScalarEvolutionExpanderTest, SCEVZeroExtendExprNonIntegral) {
Instruction *Ret = Builder.CreateRetVoid();
ScalarEvolution SE = buildSE(*F);
- auto *AddRec =
+ const SCEV *AddRec =
SE.getAddRecExpr(SE.getUnknown(GepBase), SE.getConstant(T_int64, 1),
LI->getLoopFor(L), SCEV::FlagNUW);
@@ -762,7 +762,7 @@ TEST_F(ScalarEvolutionExpanderTest, SCEVExpandNonAffineAddRec) {
SCEVExpander Exp(SE, M->getDataLayout(), "expander");
auto *InsertAt = I.getNextNode();
Value *V = Exp.expandCodeFor(AR, nullptr, InsertAt);
- auto *ExpandedAR = SE.getSCEV(V);
+ const SCEV *ExpandedAR = SE.getSCEV(V);
// Check that the expansion happened literally.
EXPECT_EQ(AR, ExpandedAR);
});
@@ -811,7 +811,7 @@ TEST_F(ScalarEvolutionExpanderTest, SCEVExpandNonAffineAddRec) {
SCEVExpander Exp(SE, M->getDataLayout(), "expander");
auto *InsertAt = I.getNextNode();
Value *V = Exp.expandCodeFor(AR, nullptr, InsertAt);
- auto *ExpandedAR = SE.getSCEV(V);
+ const SCEV *ExpandedAR = SE.getSCEV(V);
// Check that the expansion happened literally.
EXPECT_EQ(AR, ExpandedAR);
});
@@ -866,7 +866,7 @@ TEST_F(ScalarEvolutionExpanderTest, SCEVExpandNonAffineAddRec) {
SCEVExpander Exp(SE, M->getDataLayout(), "expander");
auto *InsertAt = I.getNextNode();
Value *V = Exp.expandCodeFor(AR, nullptr, InsertAt);
- auto *ExpandedAR = SE.getSCEV(V);
+ const SCEV *ExpandedAR = SE.getSCEV(V);
// Check that the expansion happened literally.
EXPECT_EQ(AR, ExpandedAR);
});