Index: lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- lib/Transforms/Scalar/JumpThreading.cpp +++ lib/Transforms/Scalar/JumpThreading.cpp @@ -504,6 +504,13 @@ if (CmpInst *Cmp = dyn_cast(I)) { assert(Preference == WantInteger && "Compares only produce integers"); PHINode *PN = dyn_cast(Cmp->getOperand(0)); + + // Look through llvm.expect as its source value could be a PHI. + if (!PN) { + if (IntrinsicInst *II = dyn_cast(Cmp->getOperand(0))) + if (II->getIntrinsicID() == Intrinsic::expect) + PN = dyn_cast(II->getArgOperand(0)); + } if (PN && PN->getParent() == BB) { // We can do this simplification if any comparisons fold to true or false. // See if any do. Index: test/Transforms/JumpThreading/expect.ll =================================================================== --- /dev/null +++ test/Transforms/JumpThreading/expect.ll @@ -0,0 +1,35 @@ +; There should be no phi nodes left. +; RUN: opt < %s -jump-threading -S | FileCheck %s + +; CHECK-NOT: phi + +declare i64 @f1() +declare i64 @f2() +declare void @f3() + +define i64 @test(i1 %cond) { + br i1 %cond, label %T1, label %F1 + +T1: + %v1 = call i64 @f1() + br label %Merge + +F1: + %v2 = call i64 @f2() + br label %Merge + +Merge: + %B = phi i64 [%v1, %T1], [12, %F1] + %expect = call i64 @llvm.expect.i64(i64 %B, i64 42) + %A = icmp ne i64 %expect, 42 + br i1 %A, label %T2, label %F2 + +T2: + call void @f3() + ret i64 1 + +F2: + ret i64 0 +} + +declare i64 @llvm.expect.i64(i64, i64)