Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -617,6 +617,7 @@ // "X < 4" and "X < 3" is known true but "X < 4" itself is not available. // Perhaps getConstantOnEdge should be smart enough to do this? + DDT->flush(); // LVI analysis relies on an up-to-date DominatorTree. for (BasicBlock *P : predecessors(BB)) { // If the value is known by LazyValueInfo to be a constant in a // predecessor, use that information to try to thread this block. @@ -630,6 +631,7 @@ /// If I is a PHI node, then we know the incoming values for any constants. if (PHINode *PN = dyn_cast(I)) { + DDT->flush(); // LVI analysis relies on an up-to-date DominatorTree. for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { Value *InVal = PN->getIncomingValue(i); if (Constant *KC = getKnownConstant(InVal, Preference)) { @@ -769,6 +771,7 @@ if (!isa(RHS)) continue; + DDT->flush(); // LVI analysis relies on an up-to-date DominatorTree. LazyValueInfo::Tristate ResT = LVI->getPredicateOnEdge(Pred, LHS, cast(RHS), PredBB, BB, @@ -792,6 +795,7 @@ if (!isa(CmpLHS) || cast(CmpLHS)->getParent() != BB) { + DDT->flush(); // LVI analysis relies on an up-to-date DominatorTree. for (BasicBlock *P : predecessors(BB)) { // If the value is known by LazyValueInfo to be a constant in a // predecessor, use that information to try to thread this block. @@ -820,6 +824,7 @@ match(CmpLHS, m_Add(m_Value(AddLHS), m_ConstantInt(AddConst)))) { if (!isa(AddLHS) || cast(AddLHS)->getParent() != BB) { + DDT->flush(); // LVI analysis relies on an up-to-date DominatorTree. for (BasicBlock *P : predecessors(BB)) { // If the value is known by LazyValueInfo to be a ConstantRange in // a predecessor, use that information to try to thread this @@ -900,6 +905,7 @@ } } + DDT->flush(); // LVI analysis relies on an up-to-date DominatorTree. // If all else fails, see if LVI can figure out a constant value for us. Constant *CI = LVI->getConstant(V, BB, CxtI); if (Constant *KC = getKnownConstant(CI, Preference)) { @@ -1101,7 +1107,7 @@ // unconditional. Because its no longer interesting as far as jump // threading is concerned. assert(CondBr->isConditional() && "Threading on unconditional terminator"); - + DDT->flush(); // LVI analysis relies on an up-to-date DominatorTree. LazyValueInfo::Tristate Ret = LVI->getPredicateAt(CondCmp->getPredicate(), CondCmp->getOperand(0), CondConst, CondBr); @@ -2371,6 +2377,7 @@ // Now check if one of the select values would allow us to constant fold the // terminator in BB. We don't do the transform if both sides fold, those // cases will be threaded in any case. + DDT->flush(); // LVI analysis relies on an up-to-date DominatorTree. LazyValueInfo::Tristate LHSFolds = LVI->getPredicateOnEdge(CondCmp->getPredicate(), SI->getOperand(1), CondRHS, Pred, BB, CondCmp); Index: llvm/test/Transforms/JumpThreading/pr36133.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/JumpThreading/pr36133.ll @@ -0,0 +1,44 @@ +; RUN: opt -jump-threading -S < %s | FileCheck %s +@global = external global i8*, align 8 + +define i32 @foo(i32 %arg) { +; CHECK-LABEL: @foo +; CHECK-LABEL: bb: +; CHECK: icmp eq +; CHECK-NEXT: br i1 %tmp1, label %bb7, label %bb7 +bb: + %tmp = load i8*, i8** @global, align 8 + %tmp1 = icmp eq i8* %tmp, null + br i1 %tmp1, label %bb3, label %bb2 + +; CHECK-NOT: bb2: +bb2: + br label %bb3 + +; CHECK-NOT: bb3: +bb3: + %tmp4 = phi i8 [ 1, %bb2 ], [ 0, %bb ] + %tmp5 = icmp eq i8 %tmp4, 0 + br i1 %tmp5, label %bb7, label %bb6 + +; CHECK-NOT: bb6: +bb6: + br label %bb7 + +; CHECK-LABEL: bb7: +bb7: + %tmp8 = icmp eq i32 %arg, -1 + br i1 %tmp8, label %bb9, label %bb10 + +; CHECK-LABEL: bb9: +bb9: + ret i32 0 + +; CHECK-LABEL: bb10: +bb10: + %tmp11 = icmp sgt i32 %arg, -1 + call void @llvm.assume(i1 %tmp11) + ret i32 1 +} + +declare void @llvm.assume(i1)