From ea6ed399b29c25fb685af16eb7f722fd1649b37a Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Wed, 7 Dec 2022 19:34:42 -0600 Subject: [PATCH] [SCEV] Convert Optional to std::optional --- llvm/include/llvm/ADT/APInt.h | 5 +- llvm/include/llvm/Analysis/ScalarEvolution.h | 35 ++++---- llvm/lib/Analysis/ScalarEvolution.cpp | 104 +++++++++++----------- llvm/lib/Support/APInt.cpp | 3 +- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 2 +- llvm/unittests/ADT/APIntTest.cpp | 5 +- llvm/unittests/Analysis/ScalarEvolutionTest.cpp | 10 +-- 7 files changed, 85 insertions(+), 79 deletions(-) diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index ac9482b..c8ca617 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace llvm { @@ -2248,8 +2249,8 @@ APInt RoundingSDiv(const APInt &A, const APInt &B, APInt::Rounding RM); /// /// The returned value may have a different bit width from the input /// coefficients. -Optional SolveQuadraticEquationWrap(APInt A, APInt B, APInt C, - unsigned RangeWidth); +std::optional SolveQuadraticEquationWrap(APInt A, APInt B, APInt C, + unsigned RangeWidth); /// Compare two values, and if they are different, return the position of the /// most significant bit that is different in the values. diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index d1097fe..dde0dcc 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -25,7 +25,6 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/FoldingSet.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" @@ -40,6 +39,7 @@ #include #include #include +#include #include namespace llvm { @@ -540,7 +540,7 @@ public: /// Does not mutate the original instruction. Returns std::nullopt if it could /// not deduce more precise flags than the instruction already has, otherwise /// returns proven flags. - Optional + std::optional getStrengthenedNoWrapFlagsFromBinOp(const OverflowingBinaryOperator *OBO); /// Notify this ScalarEvolution that \p User directly uses SCEVs in \p Ops. @@ -614,7 +614,7 @@ public: /// Predicates. If successful return these ; /// The function is intended to be called from PSCEV (the caller will decide /// whether to actually add the predicates and carry out the rewrites). - Optional>> + std::optional>> createAddRecFromPHIWithCasts(const SCEVUnknown *SymbolicPHI); /// Returns an expression for a GEP @@ -1047,8 +1047,8 @@ public: /// Check whether the condition described by Pred, LHS, and RHS is true or /// false. If we know it, return the evaluation of this condition. If neither /// is proved, return std::nullopt. - Optional evaluatePredicate(ICmpInst::Predicate Pred, const SCEV *LHS, - const SCEV *RHS); + std::optional evaluatePredicate(ICmpInst::Predicate Pred, + const SCEV *LHS, const SCEV *RHS); /// Test if the given expression is known to satisfy the condition described /// by Pred, LHS, and RHS in the given Context. @@ -1058,8 +1058,9 @@ public: /// Check whether the condition described by Pred, LHS, and RHS is true or /// false in the given \p Context. If we know it, return the evaluation of /// this condition. If neither is proved, return std::nullopt. - Optional evaluatePredicateAt(ICmpInst::Predicate Pred, const SCEV *LHS, - const SCEV *RHS, const Instruction *CtxI); + std::optional evaluatePredicateAt(ICmpInst::Predicate Pred, + const SCEV *LHS, const SCEV *RHS, + const Instruction *CtxI); /// Test if the condition described by Pred, LHS, RHS is known to be true on /// every iteration of the loop of the recurrency LHS. @@ -1081,7 +1082,7 @@ public: /// Some(MonotonicallyIncreasing) and Some(MonotonicallyDecreasing) /// respectively. If we could not prove either of these facts, returns /// std::nullopt. - Optional + std::optional getMonotonicPredicateType(const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred); @@ -1097,7 +1098,7 @@ public: /// If the result of the predicate LHS `Pred` RHS is loop invariant with /// respect to L, return a LoopInvariantPredicate with LHS and RHS being /// invariants, available at L's entry. Otherwise, return std::nullopt. - Optional + std::optional getLoopInvariantPredicate(ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, const Instruction *CtxI = nullptr); @@ -1107,7 +1108,7 @@ public: /// return a LoopInvariantPredicate with LHS and RHS being invariants, /// available at L's entry. Otherwise, return std::nullopt. The predicate /// should be the loop's exit condition. - Optional + std::optional getLoopInvariantExitCondDuringFirstIterations(ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, @@ -1195,7 +1196,8 @@ public: /// frugal here since we just bail out of actually constructing and /// canonicalizing an expression in the cases where the result isn't going /// to be a constant. - Optional computeConstantDifference(const SCEV *LHS, const SCEV *RHS); + std::optional computeConstantDifference(const SCEV *LHS, + const SCEV *RHS); /// Update no-wrap flags of an AddRec. This may drop the cached info about /// this AddRec (such as range info) in case if new flags may potentially @@ -1717,8 +1719,9 @@ private: ExitLimitCache(const Loop *L, bool ExitIfTrue, bool AllowPredicates) : L(L), ExitIfTrue(ExitIfTrue), AllowPredicates(AllowPredicates) {} - Optional find(const Loop *L, Value *ExitCond, bool ExitIfTrue, - bool ControlsExit, bool AllowPredicates); + std::optional find(const Loop *L, Value *ExitCond, + bool ExitIfTrue, bool ControlsExit, + bool AllowPredicates); void insert(const Loop *L, Value *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates, const ExitLimit &EL); @@ -1735,7 +1738,7 @@ private: Value *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates); - Optional + std::optional computeExitLimitFromCondFromBinOp(ExitLimitCacheTy &Cache, const Loop *L, Value *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates); @@ -2007,7 +2010,7 @@ private: /// entry and backedge. SCEV::NoWrapFlags proveNoUnsignedWrapViaInduction(const SCEVAddRecExpr *AR); - Optional + std::optional getMonotonicPredicateTypeImpl(const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred); @@ -2071,7 +2074,7 @@ private: /// If the analysis is not successful, a mapping from the \p SymbolicPHI to /// itself (with no predicates) is recorded, and a nullptr with an empty /// predicates vector is returned as a pair. - Optional>> + std::optional>> createAddRecFromPHIWithCastsImpl(const SCEVUnknown *SymbolicPHI); /// Compute the maximum backedge count based on the range of values diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 61a4895..382174b 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -65,7 +65,6 @@ #include "llvm/ADT/EquivalenceClasses.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/Sequence.h" @@ -2354,7 +2353,7 @@ bool ScalarEvolution::willNotOverflow(Instruction::BinaryOps BinOp, bool Signed, return isKnownPredicateAt(Pred, LHS, getConstant(Limit), CtxI); } -Optional +std::optional ScalarEvolution::getStrengthenedNoWrapFlagsFromBinOp( const OverflowingBinaryOperator *OBO) { // It cannot be done any better. @@ -3935,8 +3934,8 @@ namespace { class SCEVSequentialMinMaxDeduplicatingVisitor final : public SCEVVisitor> { - using RetVal = Optional; + std::optional> { + using RetVal = std::optional; using Base = SCEVVisitor; ScalarEvolution &SE; @@ -4872,7 +4871,7 @@ public: switch (I->getOpcode()) { case Instruction::Select: { SelectInst *SI = cast(I); - Optional Res = + std::optional Res = compareWithBackedgeCondition(SI->getCondition()); if (Res) { bool IsOne = cast(Res.value())->getValue()->isOne(); @@ -4881,7 +4880,7 @@ public: break; } default: { - Optional Res = compareWithBackedgeCondition(I); + std::optional Res = compareWithBackedgeCondition(I); if (Res) Result = Res.value(); break; @@ -4897,7 +4896,7 @@ private: : SCEVRewriteVisitor(SE), L(L), BackedgeCond(BECond), IsPositiveBECond(IsPosBECond) {} - Optional compareWithBackedgeCondition(Value *IC); + std::optional compareWithBackedgeCondition(Value *IC); const Loop *L; /// Loop back condition. @@ -4906,7 +4905,7 @@ private: bool IsPositiveBECond; }; -Optional +std::optional SCEVBackedgeConditionFolder::compareWithBackedgeCondition(Value *IC) { // If value matches the backedge condition for loop latch, @@ -5334,7 +5333,7 @@ static const Loop *isIntegerLoopHeaderPHI(const PHINode *PN, LoopInfo &LI) { // which correspond to a phi->trunc->add->sext/zext->phi update chain. // // 3) Outline common code with createAddRecFromPHI to avoid duplication. -Optional>> +std::optional>> ScalarEvolution::createAddRecFromPHIWithCastsImpl(const SCEVUnknown *SymbolicPHI) { SmallVector Predicates; @@ -5545,7 +5544,7 @@ ScalarEvolution::createAddRecFromPHIWithCastsImpl(const SCEVUnknown *SymbolicPHI return PredRewrite; } -Optional>> +std::optional>> ScalarEvolution::createAddRecFromPHIWithCasts(const SCEVUnknown *SymbolicPHI) { auto *PN = cast(SymbolicPHI->getValue()); const Loop *L = isIntegerLoopHeaderPHI(PN, LI); @@ -5567,7 +5566,7 @@ ScalarEvolution::createAddRecFromPHIWithCasts(const SCEVUnknown *SymbolicPHI) { return Rewrite; } - Optional>> + std::optional>> Rewrite = createAddRecFromPHIWithCastsImpl(SymbolicPHI); // Record in the cache that the analysis failed @@ -6122,7 +6121,7 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond( return getUnknown(I); } -static Optional +static std::optional createNodeForSelectViaUMinSeq(ScalarEvolution *SE, const SCEV *CondExpr, const SCEV *TrueExpr, const SCEV *FalseExpr) { assert(CondExpr->getType()->isIntegerTy(1) && @@ -6155,10 +6154,9 @@ createNodeForSelectViaUMinSeq(ScalarEvolution *SE, const SCEV *CondExpr, /*Sequential=*/true)); } -static Optional createNodeForSelectViaUMinSeq(ScalarEvolution *SE, - Value *Cond, - Value *TrueVal, - Value *FalseVal) { +static std::optional +createNodeForSelectViaUMinSeq(ScalarEvolution *SE, Value *Cond, Value *TrueVal, + Value *FalseVal) { if (!isa(TrueVal) && !isa(FalseVal)) return std::nullopt; @@ -6179,7 +6177,7 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIViaUMinSeq( if (!V->getType()->isIntegerTy(1)) return getUnknown(V); - if (Optional S = + if (std::optional S = createNodeForSelectViaUMinSeq(this, Cond, TrueVal, FalseVal)) return *S; @@ -6308,7 +6306,7 @@ uint32_t ScalarEvolution::GetMinTrailingZeros(const SCEV *S) { } /// Helper method to assign a range to V from metadata present in the IR. -static Optional GetRangeFromMetadata(Value *V) { +static std::optional GetRangeFromMetadata(Value *V) { if (Instruction *I = dyn_cast(V)) if (MDNode *MD = I->getMetadata(LLVMContext::MD_range)) return getConstantRangeFromMetadata(*MD); @@ -6708,7 +6706,7 @@ const ConstantRange &ScalarEvolution::getRangeRef( if (const SCEVUnknown *U = dyn_cast(S)) { // Check if the IR explicitly contains !range metadata. - Optional MDRange = GetRangeFromMetadata(U->getValue()); + std::optional MDRange = GetRangeFromMetadata(U->getValue()); if (MDRange) ConservativeResult = ConservativeResult.intersectWith(MDRange.value(), RangeType); @@ -8820,7 +8818,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCond( ControlsExit, AllowPredicates); } -Optional +std::optional ScalarEvolution::ExitLimitCache::find(const Loop *L, Value *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates) { @@ -8927,7 +8925,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCondImpl( return computeExitCountExhaustively(L, ExitCond, ExitIfTrue); } -Optional +std::optional ScalarEvolution::computeExitLimitFromCondFromBinOp( ExitLimitCacheTy &Cache, const Loop *L, Value *ExitCond, bool ExitIfTrue, bool ControlsExit, bool AllowPredicates) { @@ -10088,7 +10086,8 @@ GetQuadraticEquation(const SCEVAddRecExpr *AddRec) { /// (a) if X and Y both exist, return min(X, Y), /// (b) if neither X nor Y exist, return std::nullopt, /// (c) if exactly one of X and Y exists, return that value. -static Optional MinOptional(Optional X, Optional Y) { +static std::optional MinOptional(std::optional X, + std::optional Y) { if (X && Y) { unsigned W = std::max(X->getBitWidth(), Y->getBitWidth()); APInt XW = X->sext(W); @@ -10111,7 +10110,8 @@ static Optional MinOptional(Optional X, Optional Y) { /// coefficients. The reason is that the coefficients of the quadratic /// equation are BW+1 bits wide (to avoid truncation when converting from /// the addrec to the equation). -static Optional TruncIfPossible(Optional X, unsigned BitWidth) { +static std::optional TruncIfPossible(std::optional X, + unsigned BitWidth) { if (!X) return std::nullopt; unsigned W = X->getBitWidth(); @@ -10134,7 +10134,7 @@ static Optional TruncIfPossible(Optional X, unsigned BitWidth) { /// (b) SolveQuadraticEquationWrap was unable to find a solution. For cases /// like x^2 = 5, no integer solutions exist, in other cases an integer /// solution may exist, but SolveQuadraticEquationWrap may fail to find it. -static Optional +static std::optional SolveQuadraticAddRecExact(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) { APInt A, B, C, M; unsigned BitWidth; @@ -10144,7 +10144,8 @@ SolveQuadraticAddRecExact(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) { std::tie(A, B, C, M, BitWidth) = *T; LLVM_DEBUG(dbgs() << __func__ << ": solving for unsigned overflow\n"); - Optional X = APIntOps::SolveQuadraticEquationWrap(A, B, C, BitWidth+1); + std::optional X = + APIntOps::SolveQuadraticEquationWrap(A, B, C, BitWidth + 1); if (!X) return std::nullopt; @@ -10166,7 +10167,7 @@ SolveQuadraticAddRecExact(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) { /// (a) the addrec coefficients are not constant, or /// (b) SolveQuadraticEquationWrap was unable to find a solution for the /// bounds of the range. -static Optional +static std::optional SolveQuadraticAddRecRange(const SCEVAddRecExpr *AddRec, const ConstantRange &Range, ScalarEvolution &SE) { assert(AddRec->getOperand(0)->isZero() && @@ -10192,14 +10193,15 @@ SolveQuadraticAddRecRange(const SCEVAddRecExpr *AddRec, // cannot make any conclusions. // Return a pair: the optional solution and a flag indicating if the // solution was found. - auto SolveForBoundary = [&](APInt Bound) -> std::pair,bool> { + auto SolveForBoundary = + [&](APInt Bound) -> std::pair, bool> { // Solve for signed overflow and unsigned overflow, pick the lower // solution. LLVM_DEBUG(dbgs() << "SolveQuadraticAddRecRange: checking boundary " << Bound << " (before multiplying by " << M << ")\n"); Bound *= M; // The quadratic equation multiplier. - Optional SO; + std::optional SO; if (BitWidth > 1) { LLVM_DEBUG(dbgs() << "SolveQuadraticAddRecRange: solving for " "signed overflow\n"); @@ -10207,8 +10209,8 @@ SolveQuadraticAddRecRange(const SCEVAddRecExpr *AddRec, } LLVM_DEBUG(dbgs() << "SolveQuadraticAddRecRange: solving for " "unsigned overflow\n"); - Optional UO = APIntOps::SolveQuadraticEquationWrap(A, B, -Bound, - BitWidth+1); + std::optional UO = + APIntOps::SolveQuadraticEquationWrap(A, B, -Bound, BitWidth + 1); auto LeavesRange = [&] (const APInt &X) { ConstantInt *C0 = ConstantInt::get(SE.getContext(), X); @@ -10231,10 +10233,10 @@ SolveQuadraticAddRecRange(const SCEVAddRecExpr *AddRec, // Check the smaller value first to see if it leaves the range. // At this point, both SO and UO must have values. - Optional Min = MinOptional(SO, UO); + std::optional Min = MinOptional(SO, UO); if (LeavesRange(*Min)) return { Min, true }; - Optional Max = Min == SO ? UO : SO; + std::optional Max = Min == SO ? UO : SO; if (LeavesRange(*Max)) return { Max, true }; @@ -10800,9 +10802,9 @@ bool ScalarEvolution::isKnownPredicate(ICmpInst::Predicate Pred, return isKnownViaNonRecursiveReasoning(Pred, LHS, RHS); } -Optional ScalarEvolution::evaluatePredicate(ICmpInst::Predicate Pred, - const SCEV *LHS, - const SCEV *RHS) { +std::optional ScalarEvolution::evaluatePredicate(ICmpInst::Predicate Pred, + const SCEV *LHS, + const SCEV *RHS) { if (isKnownPredicate(Pred, LHS, RHS)) return true; else if (isKnownPredicate(ICmpInst::getInversePredicate(Pred), LHS, RHS)) @@ -10818,11 +10820,10 @@ bool ScalarEvolution::isKnownPredicateAt(ICmpInst::Predicate Pred, isBasicBlockEntryGuardedByCond(CtxI->getParent(), Pred, LHS, RHS); } -Optional ScalarEvolution::evaluatePredicateAt(ICmpInst::Predicate Pred, - const SCEV *LHS, - const SCEV *RHS, - const Instruction *CtxI) { - Optional KnownWithoutContext = evaluatePredicate(Pred, LHS, RHS); +std::optional +ScalarEvolution::evaluatePredicateAt(ICmpInst::Predicate Pred, const SCEV *LHS, + const SCEV *RHS, const Instruction *CtxI) { + std::optional KnownWithoutContext = evaluatePredicate(Pred, LHS, RHS); if (KnownWithoutContext) return KnownWithoutContext; @@ -10843,7 +10844,7 @@ bool ScalarEvolution::isKnownOnEveryIteration(ICmpInst::Predicate Pred, isLoopBackedgeGuardedByCond(L, Pred, LHS->getPostIncExpr(*this), RHS); } -Optional +std::optional ScalarEvolution::getMonotonicPredicateType(const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred) { auto Result = getMonotonicPredicateTypeImpl(LHS, Pred); @@ -10864,7 +10865,7 @@ ScalarEvolution::getMonotonicPredicateType(const SCEVAddRecExpr *LHS, return Result; } -Optional +std::optional ScalarEvolution::getMonotonicPredicateTypeImpl(const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred) { // A zero step value for LHS means the induction variable is essentially a @@ -10908,7 +10909,7 @@ ScalarEvolution::getMonotonicPredicateTypeImpl(const SCEVAddRecExpr *LHS, } } -Optional +std::optional ScalarEvolution::getLoopInvariantPredicate(ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, @@ -10994,7 +10995,7 @@ ScalarEvolution::getLoopInvariantPredicate(ICmpInst::Predicate Pred, return std::nullopt; } -Optional +std::optional ScalarEvolution::getLoopInvariantExitCondDuringFirstIterations( ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, const Instruction *CtxI, const SCEV *MaxIter) { @@ -11775,8 +11776,8 @@ bool ScalarEvolution::splitBinaryAdd(const SCEV *Expr, return true; } -Optional ScalarEvolution::computeConstantDifference(const SCEV *More, - const SCEV *Less) { +std::optional +ScalarEvolution::computeConstantDifference(const SCEV *More, const SCEV *Less) { // We avoid subtracting expressions here because this function is usually // fairly deep in the call stack (i.e. is called many times). @@ -11933,8 +11934,8 @@ bool ScalarEvolution::isImpliedCondOperandsViaNoOverflow( // neither necessary nor sufficient to prove "(FoundLHS + C) s< (FoundRHS + // C)". - Optional LDiff = computeConstantDifference(LHS, FoundLHS); - Optional RDiff = computeConstantDifference(RHS, FoundRHS); + std::optional LDiff = computeConstantDifference(LHS, FoundLHS); + std::optional RDiff = computeConstantDifference(RHS, FoundRHS); if (!LDiff || !RDiff || *LDiff != *RDiff) return false; @@ -12476,7 +12477,7 @@ bool ScalarEvolution::isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred, // reduce the compile time impact of this optimization. return false; - Optional Addend = computeConstantDifference(LHS, FoundLHS); + std::optional Addend = computeConstantDifference(LHS, FoundLHS); if (!Addend) return false; @@ -14404,8 +14405,9 @@ private: const SCEV *convertToAddRecWithPreds(const SCEVUnknown *Expr) { if (!isa(Expr->getValue())) return Expr; - Optional>> - PredicatedRewrite = SE.createAddRecFromPHIWithCasts(Expr); + std::optional< + std::pair>> + PredicatedRewrite = SE.createAddRecFromPHIWithCasts(Expr); if (!PredicatedRewrite) return Expr; for (const auto *P : PredicatedRewrite->second){ diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index ba2b2c1..b19de75 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include +#include using namespace llvm; @@ -2770,7 +2771,7 @@ APInt llvm::APIntOps::RoundingSDiv(const APInt &A, const APInt &B, llvm_unreachable("Unknown APInt::Rounding enum"); } -Optional +std::optional llvm::APIntOps::SolveQuadraticEquationWrap(APInt A, APInt B, APInt C, unsigned RangeWidth) { unsigned CoeffWidth = A.getBitWidth(); diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 72779ab..3d80613 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -6436,7 +6436,7 @@ static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE, // Create an offset-based salvage expression if possible, as it requires // less DWARF ops than an iteration count-based expression. - if (Optional Offset = + if (std::optional Offset = SE.computeConstantDifference(DVIRec.SCEVs[i], SCEVInductionVar)) { if (Offset.value().getMinSignedBits() <= 64) SalvageExpr->createOffsetExpr(Offset.value().getSExtValue(), diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index c5a9859..b306a6d 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -2895,9 +2895,8 @@ TEST(APIntTest, SolveQuadraticEquationWrap) { continue; for (int B = Low; B != High; ++B) { for (int C = Low; C != High; ++C) { - Optional S = APIntOps::SolveQuadraticEquationWrap( - APInt(Width, A), APInt(Width, B), - APInt(Width, C), Width); + std::optional S = APIntOps::SolveQuadraticEquationWrap( + APInt(Width, A), APInt(Width, B), APInt(Width, C), Width); if (S) Validate(A, B, C, Width, S->getSExtValue()); } diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp index 1470822..c6821fa 100644 --- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp @@ -58,11 +58,11 @@ protected: Test(*F, *LI, SE); } - static Optional computeConstantDifference(ScalarEvolution &SE, - const SCEV *LHS, - const SCEV *RHS) { - return SE.computeConstantDifference(LHS, RHS); - } +static std::optional computeConstantDifference(ScalarEvolution &SE, + const SCEV *LHS, + const SCEV *RHS) { + return SE.computeConstantDifference(LHS, RHS); +} static bool matchURem(ScalarEvolution &SE, const SCEV *Expr, const SCEV *&LHS, const SCEV *&RHS) { -- 2.7.4