summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp36
1 files changed, 5 insertions, 31 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index ec50b8a05f4..13812b1175f 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2176,29 +2176,6 @@ static bool implies(Value *A, Value *B) {
return false;
}
-static ConstantRange GetConstantRangeFromMetadata(MDNode *Ranges, uint32_t BitWidth) {
- const unsigned NumRanges = Ranges->getNumOperands() / 2;
- assert(NumRanges >= 1);
-
- ConstantRange CR(BitWidth, false);
- for (unsigned i = 0; i < NumRanges; ++i) {
- auto *Low =
- mdconst::extract<ConstantInt>(Ranges->getOperand(2 * i + 0));
- auto *High =
- mdconst::extract<ConstantInt>(Ranges->getOperand(2 * i + 1));
-
- // Union will merge two ranges to one and potentially introduce a range
- // not covered by the original two ranges. For example, [1, 5) and [8, 10)
- // will become [1, 10). In this case, we can not fold comparison between
- // constant 6 and a value of the above ranges. In practice, most values
- // have only one range, so it might not be worth handling this by
- // introducing additional complexity.
- CR = CR.unionWith(ConstantRange(Low->getValue(), High->getValue()));
- }
-
- return CR;
-}
-
/// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
/// fold the result. If not, this returns null.
static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
@@ -2447,8 +2424,7 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
if (auto *I = dyn_cast<Instruction>(LHS))
if (auto *Ranges = I->getMetadata(LLVMContext::MD_range))
- LHS_CR =
- LHS_CR.intersectWith(GetConstantRangeFromMetadata(Ranges, Width));
+ LHS_CR = LHS_CR.intersectWith(getConstantRangeFromMetadata(*Ranges));
if (!LHS_CR.isFullSet()) {
if (RHS_CR.contains(LHS_CR))
@@ -2466,12 +2442,10 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
if (RHS_Instr->getMetadata(LLVMContext::MD_range) &&
LHS_Instr->getMetadata(LLVMContext::MD_range)) {
- uint32_t BitWidth = Q.DL.getTypeSizeInBits(RHS->getType());
-
- auto RHS_CR = GetConstantRangeFromMetadata(
- RHS_Instr->getMetadata(LLVMContext::MD_range), BitWidth);
- auto LHS_CR = GetConstantRangeFromMetadata(
- LHS_Instr->getMetadata(LLVMContext::MD_range), BitWidth);
+ auto RHS_CR = getConstantRangeFromMetadata(
+ *RHS_Instr->getMetadata(LLVMContext::MD_range));
+ auto LHS_CR = getConstantRangeFromMetadata(
+ *LHS_Instr->getMetadata(LLVMContext::MD_range));
auto Satisfied_CR = ConstantRange::makeSatisfyingICmpRegion(Pred, RHS_CR);
if (Satisfied_CR.contains(LHS_CR))
OpenPOWER on IntegriCloud