diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -1111,6 +1111,8 @@ << '\n'); ++NumFolds; ConstantFoldTerminator(BB, true, nullptr, DTU); + if (HasProfileData) + BPI->eraseBlock(BB); return true; } @@ -1166,6 +1168,8 @@ } DTU->applyUpdatesPermissive( {{DominatorTree::Delete, BB, ToRemoveSucc}}); + if (HasProfileData) + BPI->eraseBlock(BB); return true; } @@ -1263,6 +1267,8 @@ UncondBI->setDebugLoc(BI->getDebugLoc()); BI->eraseFromParent(); DTU->applyUpdatesPermissive({{DominatorTree::Delete, BB, RemoveSucc}}); + if (HasProfileData) + BPI->eraseBlock(BB); return true; } CurrentBB = CurrentPred; diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-4.ll b/llvm/test/Transforms/JumpThreading/thread-prob-4.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/JumpThreading/thread-prob-4.ll @@ -0,0 +1,29 @@ +; RUN: opt -debug-only=branch-prob -jump-threading -S %s 2>&1 | FileCheck %s +; REQUIRES: asserts + +; Make sure that we clear edge probabilities for bb1 as we fold +; the conditional branch in it. + +; CHECK: eraseBlock bb1 + +define i32 @foo(i32 %arg) !prof !0 { +; CHECK-LABEL: @foo + %cond1 = icmp eq i32 %arg, 42 + br i1 %cond1, label %bb1, label %bb2 + +bb2: + ret i32 2 + +bb1: + %cond2 = icmp eq i32 %arg, 42 + br i1 %cond2, label %bb3, label %bb4 + +bb3: + ret i32 3 + +bb4: +; CHECK-NOT: bb4: + ret i32 4 +} + +!0 = !{!"function_entry_count", i64 0} diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-5.ll b/llvm/test/Transforms/JumpThreading/thread-prob-5.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/JumpThreading/thread-prob-5.ll @@ -0,0 +1,28 @@ +; RUN: opt -debug-only=branch-prob -jump-threading -S %s 2>&1 | FileCheck %s +; REQUIRES: asserts + +; Make sure that we clear edge probabilities for bb1 as we fold +; the conditional branch in it. + +; CHECK: eraseBlock bb1 + +define void @foo(i32 %i, i32 %len) !prof !0 { +; CHECK-LABEL: @foo + %i.inc = add nuw i32 %i, 1 + %c0 = icmp ult i32 %i.inc, %len + br i1 %c0, label %bb1, label %bb2 + +bb1: +; CHECK: bb1: + %c1 = icmp ult i32 %i, %len + br i1 %c1, label %bb2, label %bb3 + +bb2: + ret void + +bb3: +; CHECK-NOT: bb3: + ret void +} + +!0 = !{!"function_entry_count", i64 0} diff --git a/llvm/test/Transforms/JumpThreading/thread-prob-6.ll b/llvm/test/Transforms/JumpThreading/thread-prob-6.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/JumpThreading/thread-prob-6.ll @@ -0,0 +1,22 @@ +; RUN: opt -debug-only=branch-prob -jump-threading -S %s 2>&1 | FileCheck %s +; REQUIRES: asserts + +; Make sure that we clear edge probabilities for bb1 as we fold +; the conditional branch in it. + +; CHECK: eraseBlock bb1 + +define i32 @foo() !prof !0 { +; CHECK-LABEL: @foo +bb1: + br i1 true, label %bb2, label %bb3 + +bb2: + ret i32 3 + +bb3: +; CHECK-NOT: bb3: + ret i32 7 +} + +!0 = !{!"function_entry_count", i64 0}