diff options
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index c59cf3f..a777151 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6732,7 +6732,7 @@ static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS, /// Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred /// ALHS ARHS" is true. Otherwise, return std::nullopt. -static Optional<bool> +static std::optional<bool> isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS, const Value *ARHS, const Value *BLHS, const Value *BRHS, const DataLayout &DL, unsigned Depth) { @@ -6769,9 +6769,9 @@ static bool areMatchingOperands(const Value *L0, const Value *L1, const Value *R /// Return true if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is true. /// Return false if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is false. /// Otherwise, return std::nullopt if we can't infer anything. -static Optional<bool> isImpliedCondMatchingOperands(CmpInst::Predicate LPred, - CmpInst::Predicate RPred, - bool AreSwappedOps) { +static std::optional<bool> +isImpliedCondMatchingOperands(CmpInst::Predicate LPred, + CmpInst::Predicate RPred, bool AreSwappedOps) { // Canonicalize the predicate as if the operands were not commuted. if (AreSwappedOps) RPred = ICmpInst::getSwappedPredicate(RPred); @@ -6787,7 +6787,7 @@ static Optional<bool> isImpliedCondMatchingOperands(CmpInst::Predicate LPred, /// Return true if "icmp LPred X, LC" implies "icmp RPred X, RC" is true. /// Return false if "icmp LPred X, LC" implies "icmp RPred X, RC" is false. /// Otherwise, return std::nullopt if we can't infer anything. -static Optional<bool> isImpliedCondCommonOperandWithConstants( +static std::optional<bool> isImpliedCondCommonOperandWithConstants( CmpInst::Predicate LPred, const APInt &LC, CmpInst::Predicate RPred, const APInt &RC) { ConstantRange DomCR = ConstantRange::makeExactICmpRegion(LPred, LC); @@ -6804,11 +6804,11 @@ static Optional<bool> isImpliedCondCommonOperandWithConstants( /// Return true if LHS implies RHS (expanded to its components as "R0 RPred R1") /// is true. Return false if LHS implies RHS is false. Otherwise, return /// std::nullopt if we can't infer anything. -static Optional<bool> isImpliedCondICmps(const ICmpInst *LHS, - CmpInst::Predicate RPred, - const Value *R0, const Value *R1, - const DataLayout &DL, bool LHSIsTrue, - unsigned Depth) { +static std::optional<bool> isImpliedCondICmps(const ICmpInst *LHS, + CmpInst::Predicate RPred, + const Value *R0, const Value *R1, + const DataLayout &DL, + bool LHSIsTrue, unsigned Depth) { Value *L0 = LHS->getOperand(0); Value *L1 = LHS->getOperand(1); @@ -6838,7 +6838,7 @@ static Optional<bool> isImpliedCondICmps(const ICmpInst *LHS, /// false. Otherwise, return std::nullopt if we can't infer anything. We /// expect the RHS to be an icmp and the LHS to be an 'and', 'or', or a 'select' /// instruction. -static Optional<bool> +static std::optional<bool> isImpliedCondAndOr(const Instruction *LHS, CmpInst::Predicate RHSPred, const Value *RHSOp0, const Value *RHSOp1, const DataLayout &DL, bool LHSIsTrue, unsigned Depth) { @@ -6857,10 +6857,10 @@ isImpliedCondAndOr(const Instruction *LHS, CmpInst::Predicate RHSPred, if ((!LHSIsTrue && match(LHS, m_LogicalOr(m_Value(ALHS), m_Value(ARHS)))) || (LHSIsTrue && match(LHS, m_LogicalAnd(m_Value(ALHS), m_Value(ARHS))))) { // FIXME: Make this non-recursion. - if (Optional<bool> Implication = isImpliedCondition( + if (std::optional<bool> Implication = isImpliedCondition( ALHS, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue, Depth + 1)) return Implication; - if (Optional<bool> Implication = isImpliedCondition( + if (std::optional<bool> Implication = isImpliedCondition( ARHS, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue, Depth + 1)) return Implication; return std::nullopt; @@ -6868,7 +6868,7 @@ isImpliedCondAndOr(const Instruction *LHS, CmpInst::Predicate RHSPred, return std::nullopt; } -Optional<bool> +std::optional<bool> llvm::isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred, const Value *RHSOp0, const Value *RHSOp1, const DataLayout &DL, bool LHSIsTrue, unsigned Depth) { @@ -6903,9 +6903,9 @@ llvm::isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred, return std::nullopt; } -Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS, - const DataLayout &DL, bool LHSIsTrue, - unsigned Depth) { +std::optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS, + const DataLayout &DL, + bool LHSIsTrue, unsigned Depth) { // LHS ==> RHS by definition if (LHS == RHS) return LHSIsTrue; @@ -6922,21 +6922,21 @@ Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS, // LHS ==> !(RHS1 && RHS2) if LHS ==> !RHS1 or LHS ==> !RHS2 const Value *RHS1, *RHS2; if (match(RHS, m_LogicalOr(m_Value(RHS1), m_Value(RHS2)))) { - if (Optional<bool> Imp = + if (std::optional<bool> Imp = isImpliedCondition(LHS, RHS1, DL, LHSIsTrue, Depth + 1)) if (*Imp == true) return true; - if (Optional<bool> Imp = + if (std::optional<bool> Imp = isImpliedCondition(LHS, RHS2, DL, LHSIsTrue, Depth + 1)) if (*Imp == true) return true; } if (match(RHS, m_LogicalAnd(m_Value(RHS1), m_Value(RHS2)))) { - if (Optional<bool> Imp = + if (std::optional<bool> Imp = isImpliedCondition(LHS, RHS1, DL, LHSIsTrue, Depth + 1)) if (*Imp == false) return false; - if (Optional<bool> Imp = + if (std::optional<bool> Imp = isImpliedCondition(LHS, RHS2, DL, LHSIsTrue, Depth + 1)) if (*Imp == false) return false; @@ -6976,9 +6976,9 @@ getDomPredecessorCondition(const Instruction *ContextI) { return {PredCond, TrueBB == ContextBB}; } -Optional<bool> llvm::isImpliedByDomCondition(const Value *Cond, - const Instruction *ContextI, - const DataLayout &DL) { +std::optional<bool> llvm::isImpliedByDomCondition(const Value *Cond, + const Instruction *ContextI, + const DataLayout &DL) { assert(Cond->getType()->isIntOrIntVectorTy(1) && "Condition must be bool"); auto PredCond = getDomPredecessorCondition(ContextI); if (PredCond.first) @@ -6986,10 +6986,11 @@ Optional<bool> llvm::isImpliedByDomCondition(const Value *Cond, return std::nullopt; } -Optional<bool> llvm::isImpliedByDomCondition(CmpInst::Predicate Pred, - const Value *LHS, const Value *RHS, - const Instruction *ContextI, - const DataLayout &DL) { +std::optional<bool> llvm::isImpliedByDomCondition(CmpInst::Predicate Pred, + const Value *LHS, + const Value *RHS, + const Instruction *ContextI, + const DataLayout &DL) { auto PredCond = getDomPredecessorCondition(ContextI); if (PredCond.first) return isImpliedCondition(PredCond.first, Pred, LHS, RHS, DL, @@ -7431,8 +7432,9 @@ getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL) { return Offset; } -Optional<int64_t> llvm::isPointerOffset(const Value *Ptr1, const Value *Ptr2, - const DataLayout &DL) { +std::optional<int64_t> llvm::isPointerOffset(const Value *Ptr1, + const Value *Ptr2, + const DataLayout &DL) { APInt Offset1(DL.getIndexTypeSizeInBits(Ptr1->getType()), 0); APInt Offset2(DL.getIndexTypeSizeInBits(Ptr2->getType()), 0); Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(DL, Offset1, true); |