diff --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp --- a/llvm/lib/Analysis/AssumptionCache.cpp +++ b/llvm/lib/Analysis/AssumptionCache.cpp @@ -87,11 +87,11 @@ AddAffected(Cond); CmpInst::Predicate Pred; - if (match(Cond, m_ICmp(Pred, m_Value(A), m_Value(B)))) { + if (match(Cond, m_Cmp(Pred, m_Value(A), m_Value(B)))) { AddAffected(A); AddAffected(B); - if (Pred == ICmpInst::ICMP_EQ) { + if (Pred == CmpInst::ICMP_EQ) { // For equality comparisons, we handle the case of bit inversion. auto AddAffectedFromEq = [&AddAffected](Value *V) { Value *A; @@ -118,7 +118,7 @@ Value *X; // Handle (A + C1) u< C2, which is the canonical form of A > C3 && A < C4, // and recognized by LVI at least. - if (Pred == ICmpInst::ICMP_ULT && + if (Pred == CmpInst::ICMP_ULT && match(A, m_Add(m_Value(X), m_ConstantInt())) && match(B, m_ConstantInt())) AddAffected(X); diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3557,9 +3557,9 @@ return nullptr; } -static Value *simplifyICmpWithDominatingAssume(CmpInst::Predicate Predicate, - Value *LHS, Value *RHS, - const SimplifyQuery &Q) { +static Value *simplifyCmpWithDominatingAssume(CmpInst::Predicate Predicate, + Value *LHS, Value *RHS, + const SimplifyQuery &Q) { // Gracefully handle instructions that have not been inserted yet. if (!Q.AC || !Q.CxtI || !Q.CxtI->getParent()) return nullptr; @@ -3840,7 +3840,7 @@ if (Value *V = simplifyICmpWithMinMax(Pred, LHS, RHS, Q, MaxRecurse)) return V; - if (Value *V = simplifyICmpWithDominatingAssume(Pred, LHS, RHS, Q)) + if (Value *V = simplifyCmpWithDominatingAssume(Pred, LHS, RHS, Q)) return V; // Simplify comparisons of related pointers using a powerful, recursive @@ -4074,6 +4074,9 @@ } } + if (Value *V = simplifyCmpWithDominatingAssume(Pred, LHS, RHS, Q)) + return V; + // If the comparison is with the result of a select instruction, check whether // comparing with either branch of the select always yields the same value. if (isa(LHS) || isa(RHS)) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6598,7 +6598,7 @@ } } -/// Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred +/// Return true if "cmp Pred BLHS BRHS" is true whenever "cmp Pred /// ALHS ARHS" is true. Otherwise, return None. static Optional isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS, @@ -6635,15 +6635,15 @@ return IsMatchingOps || IsSwappedOps; } -/// Return true if "icmp1 APred X, Y" implies "icmp2 BPred X, Y" is true. -/// Return false if "icmp1 APred X, Y" implies "icmp2 BPred X, Y" is false. +/// Return true if "cmp1 APred X, Y" implies "cmp2 BPred X, Y" is true. +/// Return false if "cmp1 APred X, Y" implies "cmp2 BPred X, Y" is false. /// Otherwise, return None if we can't infer anything. static Optional isImpliedCondMatchingOperands(CmpInst::Predicate APred, CmpInst::Predicate BPred, bool AreSwappedOps) { // Canonicalize the predicate as if the operands were not commuted. if (AreSwappedOps) - BPred = ICmpInst::getSwappedPredicate(BPred); + BPred = CmpInst::getSwappedPredicate(BPred); if (CmpInst::isImpliedTrueByMatchingCmp(APred, BPred)) return true; @@ -6673,11 +6673,11 @@ /// Return true if LHS implies RHS is true. Return false if LHS implies RHS is /// false. Otherwise, return None if we can't infer anything. -static Optional isImpliedCondICmps(const ICmpInst *LHS, - CmpInst::Predicate BPred, - const Value *BLHS, const Value *BRHS, - const DataLayout &DL, bool LHSIsTrue, - unsigned Depth) { +static Optional isImpliedCondCmps(const CmpInst *LHS, + CmpInst::Predicate BPred, + const Value *BLHS, const Value *BRHS, + const DataLayout &DL, bool LHSIsTrue, + unsigned Depth) { Value *ALHS = LHS->getOperand(0); Value *ARHS = LHS->getOperand(1); @@ -6710,7 +6710,7 @@ /// Return true if LHS implies RHS is true. Return false if LHS implies RHS is /// false. Otherwise, return None 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. +/// LHS to be an 'and', 'or', or a 'select' instruction. static Optional isImpliedCondAndOr(const Instruction *LHS, CmpInst::Predicate RHSPred, const Value *RHSOp0, const Value *RHSOp1, @@ -6757,15 +6757,13 @@ assert(LHS->getType()->isIntOrIntVectorTy(1) && "Expected integer type only!"); - // Both LHS and RHS are icmps. - const ICmpInst *LHSCmp = dyn_cast(LHS); + // Both LHS and RHS are cmps. + const CmpInst *LHSCmp = dyn_cast(LHS); if (LHSCmp) - return isImpliedCondICmps(LHSCmp, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue, - Depth); + return isImpliedCondCmps(LHSCmp, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue, + Depth); - /// The LHS should be an 'or', 'and', or a 'select' instruction. We expect - /// the RHS to be an icmp. - /// FIXME: Add support for and/or/select on the RHS. + /// The LHS should be an 'or', 'and', or a 'select' instruction. if (const Instruction *LHSI = dyn_cast(LHS)) { if ((LHSI->getOpcode() == Instruction::And || LHSI->getOpcode() == Instruction::Or || @@ -6783,7 +6781,7 @@ if (LHS == RHS) return LHSIsTrue; - if (const ICmpInst *RHSCmp = dyn_cast(RHS)) + if (const CmpInst *RHSCmp = dyn_cast(RHS)) return isImpliedCondition(LHS, RHSCmp->getPredicate(), RHSCmp->getOperand(0), RHSCmp->getOperand(1), DL, LHSIsTrue, Depth); diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -4302,6 +4302,12 @@ case ICMP_SLT: // A