diff options
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 9 | ||||
-rw-r--r-- | llvm/test/Transforms/CorrelatedValuePropagation/guards.ll | 17 |
2 files changed, 21 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 880adacdc5a..c3329d19115 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -978,12 +978,11 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange( if (!GuardDecl || GuardDecl->use_empty()) return; - for (BasicBlock::iterator I = BBI->getIterator(), - E = BBI->getParent()->begin(); I != E; I--) { + for (Instruction &I : make_range(BBI->getIterator().getReverse(), + BBI->getParent()->rend())) { Value *Cond = nullptr; - if (!match(&*I, m_Intrinsic<Intrinsic::experimental_guard>(m_Value(Cond)))) - continue; - BBLV = intersect(BBLV, getValueFromCondition(Val, Cond)); + if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>(m_Value(Cond)))) + BBLV = intersect(BBLV, getValueFromCondition(Val, Cond)); } } diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/guards.ll b/llvm/test/Transforms/CorrelatedValuePropagation/guards.ll index 401cb2549dd..d62e512c522 100644 --- a/llvm/test/Transforms/CorrelatedValuePropagation/guards.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/guards.ll @@ -93,3 +93,20 @@ continue: %result = or i1 %dead, %alive ret i1 %result } + +; Check that we handle the case when the guard is the very first instruction in +; a basic block. +define i1 @test6(i32 %a) { +; CHECK-LABEL: @test6( +; CHECK: %alive = icmp eq i32 %a, 8 +; CHECK-NEXT: %result = or i1 false, %alive + %cmp = icmp ult i32 %a, 16 + br label %continue + +continue: + call void(i1,...) @llvm.experimental.guard(i1 %cmp) [ "deopt"() ] + %dead = icmp eq i32 %a, 16 + %alive = icmp eq i32 %a, 8 + %result = or i1 %dead, %alive + ret i1 %result +} |