804 changes: 441 additions & 363 deletions llvm/include/llvm/Analysis/ScalarEvolution.h

Large diffs are not rendered by default.

287 changes: 154 additions & 133 deletions llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion llvm/lib/Analysis/Delinearization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 12 additions & 8 deletions llvm/lib/Analysis/DependenceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,10 +1250,12 @@ bool DependenceInfo::strongSIVtest(const SCEV *Coeff, const SCEV *SrcConst,
if (const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->getType())) {
LLVM_DEBUG(dbgs() << "\t UpperBound = " << *UpperBound);
LLVM_DEBUG(dbgs() << ", " << *UpperBound->getType() << "\n");
const SCEV *AbsDelta =
SE->isKnownNonNegative(Delta) ? Delta : SE->getNegativeSCEV(Delta);
const SCEV *AbsCoeff =
SE->isKnownNonNegative(Coeff) ? Coeff : SE->getNegativeSCEV(Coeff);
const SCEV *AbsDelta = SE->isKnownNonNegative(Delta)
? Delta
: SE->getNegativeSCEV(Delta).getPointer();
const SCEV *AbsCoeff = SE->isKnownNonNegative(Coeff)
? Coeff
: SE->getNegativeSCEV(Coeff).getPointer();
const SCEV *Product = SE->getMulExpr(UpperBound, AbsCoeff);
if (isKnownPredicate(CmpInst::ICMP_SGT, AbsDelta, Product)) {
// Distance greater than trip count - no dependence
Expand Down Expand Up @@ -1791,8 +1793,9 @@ bool DependenceInfo::weakZeroSrcSIVtest(const SCEV *DstCoeff,
const SCEV *AbsCoeff =
SE->isKnownNegative(ConstCoeff) ?
SE->getNegativeSCEV(ConstCoeff) : ConstCoeff;
const SCEV *NewDelta =
SE->isKnownNegative(ConstCoeff) ? SE->getNegativeSCEV(Delta) : Delta;
const SCEV *NewDelta = SE->isKnownNegative(ConstCoeff)
? SE->getNegativeSCEV(Delta).getPointer()
: Delta;

// check that Delta/SrcCoeff < iteration count
// really check NewDelta < count*AbsCoeff
Expand Down Expand Up @@ -1900,8 +1903,9 @@ bool DependenceInfo::weakZeroDstSIVtest(const SCEV *SrcCoeff,
const SCEV *AbsCoeff =
SE->isKnownNegative(ConstCoeff) ?
SE->getNegativeSCEV(ConstCoeff) : ConstCoeff;
const SCEV *NewDelta =
SE->isKnownNegative(ConstCoeff) ? SE->getNegativeSCEV(Delta) : Delta;
const SCEV *NewDelta = SE->isKnownNegative(ConstCoeff)
? SE->getNegativeSCEV(Delta).getPointer()
: Delta;

// check that Delta/SrcCoeff < iteration count
// really check NewDelta < count*AbsCoeff
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/IVDescriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ bool InductionDescriptor::isInductionPHI(
return false;

// Check that the PHI is consecutive.
const SCEV *PhiScev = Expr ? Expr : SE->getSCEV(Phi);
const SCEV *PhiScev = Expr ? Expr : SE->getSCEV(Phi).getPointer();
const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PhiScev);

if (!AR) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/IVUsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -1091,7 +1091,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);
Expand Down Expand Up @@ -1450,7 +1450,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);
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/LoopCacheAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ bool IndexedReference::isConsecutive(const Loop &L, const SCEV *&Stride,
SE.getNoopOrSignExtend(ElemSize, WiderType));
const SCEV *CacheLineSize = SE.getConstant(Stride->getType(), CLS);

Stride = SE.isKnownNegative(Stride) ? SE.getNegativeSCEV(Stride) : Stride;
Stride = SE.isKnownNegative(Stride) ? SE.getNegativeSCEV(Stride).getPointer()
: Stride;
return SE.isKnownPredicate(ICmpInst::ICMP_ULT, Stride, CacheLineSize);
}

Expand Down
2,359 changes: 1,169 additions & 1,190 deletions llvm/lib/Analysis/ScalarEvolution.cpp

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions llvm/lib/Target/ARM/MVETailPredication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ bool InductiveRangeCheck::reassociateSubLHS(
auto getExprScaledIfOverflow = [&](Instruction::BinaryOps BinOp,
const SCEV *LHS,
const SCEV *RHS) -> const SCEV * {
const SCEV *(ScalarEvolution::*Operation)(const SCEV *, const SCEV *,
SCEV::NoWrapFlags, unsigned);
SCEVUse (ScalarEvolution:: *Operation)(SCEVUse, SCEVUse, SCEV::NoWrapFlags,
unsigned);
switch (BinOp) {
default:
llvm_unreachable("Unsupported binary op");
Expand Down Expand Up @@ -750,7 +750,7 @@ InductiveRangeCheck::computeSafeIterationSpace(ScalarEvolution &SE,
const SCEV *Zero = SE.getZero(M->getType());

// This function returns SCEV equal to 1 if X is non-negative 0 otherwise.
auto SCEVCheckNonNegative = [&](const SCEV *X) {
auto SCEVCheckNonNegative = [&](const SCEV *X) -> const SCEV * {
const Loop *L = IndVar->getLoop();
const SCEV *Zero = SE.getZero(X->getType());
const SCEV *One = SE.getOne(X->getType());
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/LoopDeletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ bool LoopIdiomRecognize::processLoopMemSet(MemSetInst *MSI,
return false;
}

const SCEV *PointerStrideSCEV = Ev->getOperand(1);
const SCEV *MemsetSizeSCEV = SE->getSCEV(MSI->getLength());
SCEVUse PointerStrideSCEV = Ev->getOperand(1);
SCEVUse MemsetSizeSCEV = SE->getSCEV(MSI->getLength());
if (!PointerStrideSCEV || !MemsetSizeSCEV)
return false;

Expand Down Expand Up @@ -885,9 +885,9 @@ bool LoopIdiomRecognize::processLoopMemSet(MemSetInst *MSI,

// Compare positive direction PointerStrideSCEV with MemsetSizeSCEV
IsNegStride = PointerStrideSCEV->isNonConstantNegative();
const SCEV *PositiveStrideSCEV =
IsNegStride ? SE->getNegativeSCEV(PointerStrideSCEV)
: PointerStrideSCEV;
SCEVUse PositiveStrideSCEV = IsNegStride
? SE->getNegativeSCEV(PointerStrideSCEV)
: PointerStrideSCEV;
LLVM_DEBUG(dbgs() << " MemsetSizeSCEV: " << *MemsetSizeSCEV << "\n"
<< " PositiveStrideSCEV: " << *PositiveStrideSCEV
<< "\n");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/LoopPredication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3232,8 +3232,9 @@ void LSRInstance::GenerateIVChain(const IVChain &Chain,
// IncExpr was the result of subtraction of two narrow values, so must
// be signed.
const SCEV *IncExpr = SE.getNoopOrSignExtend(Inc.IncExpr, IntTy);
LeftOverExpr = LeftOverExpr ?
SE.getAddExpr(LeftOverExpr, IncExpr) : IncExpr;
LeftOverExpr = LeftOverExpr
? SE.getAddExpr(LeftOverExpr, IncExpr).getPointer()
: IncExpr;
}
if (LeftOverExpr && !LeftOverExpr->isZero()) {
// Expand the IV increment.
Expand Down Expand Up @@ -3613,7 +3614,7 @@ static const SCEV *CollectSubexprs(const SCEV *S, const SCEVConstant *C,
for (const SCEV *S : Add->operands()) {
const SCEV *Remainder = CollectSubexprs(S, C, Ops, L, SE, Depth+1);
if (Remainder)
Ops.push_back(C ? SE.getMulExpr(C, Remainder) : Remainder);
Ops.push_back(C ? SE.getMulExpr(C, Remainder).getPointer() : Remainder);
}
return nullptr;
} else if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(S)) {
Expand All @@ -3626,7 +3627,7 @@ static const SCEV *CollectSubexprs(const SCEV *S, const SCEVConstant *C,
// Split the non-zero AddRec unless it is part of a nested recurrence that
// does not pertain to this loop.
if (Remainder && (AR->getLoop() == L || !isa<SCEVAddRecExpr>(Remainder))) {
Ops.push_back(C ? SE.getMulExpr(C, Remainder) : Remainder);
Ops.push_back(C ? SE.getMulExpr(C, Remainder).getPointer() : Remainder);
Remainder = nullptr;
}
if (Remainder != AR->getStart()) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,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;
}
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,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.
Expand Down Expand Up @@ -292,8 +292,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());
Expand Down Expand Up @@ -389,7 +389,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;
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,15 @@ class SCEVAddRecForUniformityRewriter
// 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);
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18687,10 +18687,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);
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll
Original file line number Diff line number Diff line change
Expand Up @@ -846,11 +846,9 @@ failed:
define i32 @test_litter_conditions_constant(i32 %start, i32 %len) {
; CHECK-LABEL: @test_litter_conditions_constant(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[START:%.*]], -1
; CHECK-NEXT: [[RANGE_CHECK_FIRST_ITER:%.*]] = icmp ult i32 [[TMP0]], [[LEN:%.*]]
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[START]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
; CHECK-NEXT: [[CANONICAL_IV:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[CANONICAL_IV_NEXT:%.*]], [[BACKEDGE]] ]
; CHECK-NEXT: [[CONSTANT_CHECK:%.*]] = icmp ult i32 [[CANONICAL_IV]], 65635
; CHECK-NEXT: br i1 [[CONSTANT_CHECK]], label [[CONSTANT_CHECK_PASSED:%.*]], label [[CONSTANT_CHECK_FAILED:%.*]]
Expand All @@ -860,8 +858,10 @@ define i32 @test_litter_conditions_constant(i32 %start, i32 %len) {
; CHECK-NEXT: [[AND_1:%.*]] = and i1 [[ZERO_CHECK]], [[FAKE_1]]
; CHECK-NEXT: br i1 [[AND_1]], label [[RANGE_CHECK_BLOCK:%.*]], label [[FAILED_1:%.*]]
; CHECK: range_check_block:
; CHECK-NEXT: [[IV_MINUS_1:%.*]] = add i32 [[IV]], -1
; CHECK-NEXT: [[RANGE_CHECK:%.*]] = icmp ult i32 [[IV_MINUS_1]], [[LEN:%.*]]
; CHECK-NEXT: [[FAKE_2:%.*]] = call i1 @cond()
; CHECK-NEXT: [[AND_2:%.*]] = and i1 [[RANGE_CHECK_FIRST_ITER]], [[FAKE_2]]
; CHECK-NEXT: [[AND_2:%.*]] = and i1 [[RANGE_CHECK]], [[FAKE_2]]
; CHECK-NEXT: br i1 [[AND_2]], label [[BACKEDGE]], label [[FAILED_2:%.*]]
; CHECK: backedge:
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
Expand Down
138 changes: 71 additions & 67 deletions llvm/unittests/Analysis/ScalarEvolutionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ static std::optional<APInt> computeConstantDifference(ScalarEvolution &SE,
return SE.computeConstantDifference(LHS, RHS);
}

static bool matchURem(ScalarEvolution &SE, const SCEV *Expr, const SCEV *&LHS,
const SCEV *&RHS) {
return SE.matchURem(Expr, LHS, RHS);
}
static bool matchURem(ScalarEvolution &SE, const SCEV *Expr, SCEVUse &LHS,
SCEVUse &RHS) {
return SE.matchURem(Expr, LHS, RHS);
}

static bool isImpliedCond(
ScalarEvolution &SE, ICmpInst::Predicate Pred, const SCEV *LHS,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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>(
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));
});
}
Expand Down Expand Up @@ -1139,13 +1139,15 @@ 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 *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 *ScevV0 = SE.getSCEV(getInstructionByName(F, "v0")); // %pp
const SCEV *ScevV3 = SE.getSCEV(getInstructionByName(F, "v3")); // (3 + %pp)
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);
Expand Down Expand Up @@ -1197,16 +1199,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)));
Expand All @@ -1227,9 +1230,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));
});
Expand All @@ -1253,16 +1256,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);
});
Expand Down Expand Up @@ -1290,7 +1294,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);
Expand Down Expand Up @@ -1325,7 +1329,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));
Expand Down Expand Up @@ -1354,8 +1358,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(
Expand Down Expand Up @@ -1397,8 +1401,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;
Expand Down Expand Up @@ -1476,8 +1480,8 @@ TEST_F(ScalarEvolutionsTest, MatchURem) {
runWithSE(*M, "test", [&](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
for (auto *N : {"rem1", "rem2", "rem3", "rem5"}) {
auto *URemI = getInstructionByName(F, N);
auto *S = SE.getSCEV(URemI);
const SCEV *LHS, *RHS;
const SCEV *S = SE.getSCEV(URemI);
SCEVUse LHS, RHS;
EXPECT_TRUE(matchURem(SE, S, LHS, RHS));
EXPECT_EQ(LHS, SE.getSCEV(URemI->getOperand(0)));
EXPECT_EQ(RHS, SE.getSCEV(URemI->getOperand(1)));
Expand All @@ -1489,8 +1493,8 @@ TEST_F(ScalarEvolutionsTest, MatchURem) {
// match results are extended to the size of the input expression.
auto *Ext = getInstructionByName(F, "ext");
auto *URem1 = getInstructionByName(F, "rem4");
auto *S = SE.getSCEV(Ext);
const SCEV *LHS, *RHS;
const SCEV *S = SE.getSCEV(Ext);
SCEVUse LHS, RHS;
EXPECT_TRUE(matchURem(SE, S, LHS, RHS));
EXPECT_NE(LHS, SE.getSCEV(URem1->getOperand(0)));
// RHS and URem1->getOperand(1) have different widths, so compare the
Expand Down Expand Up @@ -1525,8 +1529,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);
Expand Down Expand Up @@ -1578,13 +1582,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);
});
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/Transforms/Utils/LoopUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,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);
});
}
Expand All @@ -137,7 +137,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);
});
}
10 changes: 5 additions & 5 deletions llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down