From 1f7b813e2b32e72136050558b60f5d90ae2ee4b2 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Sun, 2 Oct 2016 00:09:57 +0000 Subject: [PATCH] Remove duplicated code; NFC ICmpInst::makeConstantRange does exactly the same thing as ConstantRange::makeExactICmpRegion. llvm-svn: 283059 --- llvm/include/llvm/IR/Instructions.h | 4 -- llvm/lib/Analysis/InstructionSimplify.cpp | 2 +- llvm/lib/Analysis/LazyValueInfo.cpp | 4 +- llvm/lib/Analysis/ScalarEvolution.cpp | 4 +- llvm/lib/IR/Instructions.cpp | 63 ---------------------- .../Transforms/InstCombine/InstCombineCompares.cpp | 3 +- 6 files changed, 7 insertions(+), 73 deletions(-) diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index e68767b..b5deda2 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -1185,10 +1185,6 @@ public: return !isEquality(P); } - /// Initialize a set of values that all satisfy the predicate with C. - /// Make a ConstantRange for a relation with a constant value. - static ConstantRange makeConstantRange(Predicate pred, const APInt &C); - /// Exchange the two operands to this instruction in such a way that it does /// not modify the semantics of the instruction. The predicate value may be /// changed to retain the same result if the predicate is order dependent diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 08e82cb..8d6c83b 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -2157,7 +2157,7 @@ static Value *simplifyICmpWithConstant(CmpInst::Predicate Pred, Value *LHS, return nullptr; // Rule out tautological comparisons (eg., ult 0 or uge 0). - ConstantRange RHS_CR = ICmpInst::makeConstantRange(Pred, *C); + ConstantRange RHS_CR = ConstantRange::makeExactICmpRegion(Pred, *C); if (RHS_CR.isEmptySet()) return ConstantInt::getFalse(GetCompareTy(RHS)); if (RHS_CR.isFullSet()) diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 9883154..880adac 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -1707,8 +1707,8 @@ static LazyValueInfo::Tristate getPredicateResult(unsigned Pred, Constant *C, } // Handle more complex predicates. - ConstantRange TrueValues = - ICmpInst::makeConstantRange((ICmpInst::Predicate)Pred, CI->getValue()); + ConstantRange TrueValues = ConstantRange::makeExactICmpRegion( + (ICmpInst::Predicate)Pred, CI->getValue()); if (TrueValues.contains(CR)) return LazyValueInfo::True; if (TrueValues.inverse().contains(CR)) diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 367c315..70e0c29 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -5994,8 +5994,8 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L, if (const SCEVAddRecExpr *AddRec = dyn_cast(LHS)) if (AddRec->getLoop() == L) { // Form the constant range. - ConstantRange CompRange( - ICmpInst::makeConstantRange(Cond, RHSC->getAPInt())); + ConstantRange CompRange = + ConstantRange::makeExactICmpRegion(Cond, RHSC->getAPInt()); const SCEV *Ret = AddRec->getNumIterationsInRange(CompRange, *this); if (!isa(Ret)) return Ret; diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index e29f825..dcd0feb 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -3472,69 +3472,6 @@ ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) { } } -/// Initialize a set of values that all satisfy the condition with C. -/// -ConstantRange -ICmpInst::makeConstantRange(Predicate pred, const APInt &C) { - APInt Lower(C); - APInt Upper(C); - uint32_t BitWidth = C.getBitWidth(); - switch (pred) { - default: llvm_unreachable("Invalid ICmp opcode to ConstantRange ctor!"); - case ICmpInst::ICMP_EQ: ++Upper; break; - case ICmpInst::ICMP_NE: ++Lower; break; - case ICmpInst::ICMP_ULT: - Lower = APInt::getMinValue(BitWidth); - // Check for an empty-set condition. - if (Lower == Upper) - return ConstantRange(BitWidth, /*isFullSet=*/false); - break; - case ICmpInst::ICMP_SLT: - Lower = APInt::getSignedMinValue(BitWidth); - // Check for an empty-set condition. - if (Lower == Upper) - return ConstantRange(BitWidth, /*isFullSet=*/false); - break; - case ICmpInst::ICMP_UGT: - ++Lower; Upper = APInt::getMinValue(BitWidth); // Min = Next(Max) - // Check for an empty-set condition. - if (Lower == Upper) - return ConstantRange(BitWidth, /*isFullSet=*/false); - break; - case ICmpInst::ICMP_SGT: - ++Lower; Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max) - // Check for an empty-set condition. - if (Lower == Upper) - return ConstantRange(BitWidth, /*isFullSet=*/false); - break; - case ICmpInst::ICMP_ULE: - Lower = APInt::getMinValue(BitWidth); ++Upper; - // Check for a full-set condition. - if (Lower == Upper) - return ConstantRange(BitWidth, /*isFullSet=*/true); - break; - case ICmpInst::ICMP_SLE: - Lower = APInt::getSignedMinValue(BitWidth); ++Upper; - // Check for a full-set condition. - if (Lower == Upper) - return ConstantRange(BitWidth, /*isFullSet=*/true); - break; - case ICmpInst::ICMP_UGE: - Upper = APInt::getMinValue(BitWidth); // Min = Next(Max) - // Check for a full-set condition. - if (Lower == Upper) - return ConstantRange(BitWidth, /*isFullSet=*/true); - break; - case ICmpInst::ICMP_SGE: - Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max) - // Check for a full-set condition. - if (Lower == Upper) - return ConstantRange(BitWidth, /*isFullSet=*/true); - break; - } - return ConstantRange(Lower, Upper); -} - CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) { switch (pred) { default: llvm_unreachable("Unknown cmp predicate!"); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9889930..7b59f86 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2320,7 +2320,8 @@ Instruction *InstCombiner::foldICmpAddConstant(ICmpInst &Cmp, // Fold icmp pred (add X, C2), C. Value *X = Add->getOperand(0); Type *Ty = Add->getType(); - auto CR = Cmp.makeConstantRange(Cmp.getPredicate(), *C).subtract(*C2); + auto CR = + ConstantRange::makeExactICmpRegion(Cmp.getPredicate(), *C).subtract(*C2); const APInt &Upper = CR.getUpper(); const APInt &Lower = CR.getLower(); if (Cmp.isSigned()) { -- 2.7.4