diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index b2ce163fca36c..467f46489070f 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -669,36 +669,24 @@ bool LazyValueInfoCache::solveBlockValue(Value *Val, BasicBlock *BB) { return true; } - // If this is an instruction which supports range metadata, intersect the - // implied range. - Res = intersect(Res, getFromRangeMetadata(BBI)); - - // We can only analyze the definitions of certain classes of instructions - // (integral binops and casts at the moment), so bail if this isn't one. - LVILatticeVal Result; - if ((!isa(BBI) && !isa(BBI)) || - !BBI->getType()->isIntegerTy()) { - DEBUG(dbgs() << " compute BB '" << BB->getName() - << "' - overdefined because inst def found.\n"); - Res.markOverdefined(); + if (isa(BBI) && BBI->getType()->isIntegerTy()) { + if (!solveBlockValueConstantRange(Res, BBI, BB)) + return false; insertResult(Val, BB, Res); return true; } - // FIXME: We're currently limited to binops with a constant RHS. This should - // be improved. BinaryOperator *BO = dyn_cast(BBI); - if (BO && !isa(BO->getOperand(1))) { - DEBUG(dbgs() << " compute BB '" << BB->getName() - << "' - overdefined because inst def found.\n"); - - Res.markOverdefined(); + if (BO && isa(BO->getOperand(1))) { + if (!solveBlockValueConstantRange(Res, BBI, BB)) + return false; insertResult(Val, BB, Res); return true; } - if (!solveBlockValueConstantRange(Res, BBI, BB)) - return false; + DEBUG(dbgs() << " compute BB '" << BB->getName() + << "' - unknown inst def found.\n"); + Res = getFromRangeMetadata(BBI); insertResult(Val, BB, Res); return true; } @@ -1007,7 +995,7 @@ bool LazyValueInfoCache::solveBlockValueSelect(LVILatticeVal &BBLV, bool LazyValueInfoCache::solveBlockValueConstantRange(LVILatticeVal &BBLV, Instruction *BBI, - BasicBlock *BB) { + BasicBlock *BB) { // Figure out the range of the LHS. If that fails, bail. if (!hasBlockValue(BBI->getOperand(0), BB)) { if (pushBlockValue(std::make_pair(BB, BBI->getOperand(0)))) diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/range.ll b/llvm/test/Transforms/CorrelatedValuePropagation/range.ll index 884cc8bdc125b..8ca171a286ccd 100644 --- a/llvm/test/Transforms/CorrelatedValuePropagation/range.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/range.ll @@ -189,3 +189,17 @@ define i1 @test10(i64* %p) { %res = icmp eq i64 %a, 0 ret i1 %res } + +@g = external global i32 + +define i1 @test11() { +; CHECK: @test11 +; CHECK: ret i1 true + %positive = load i32, i32* @g, !range !{i32 1, i32 2048} + %add = add i32 %positive, 1 + %test = icmp sgt i32 %add, 0 + br label %next + +next: + ret i1 %test +}