[llvm] 0e99562 - Revert "[JumpThreading] Preserve profile metadata during select unfolding"

Dmitri Gribenko via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 10 02:54:58 PST 2023


Author: Dmitri Gribenko
Date: 2023-01-10T11:54:50+01:00
New Revision: 0e9956204db3802ac94a7727bf2fe35c753cc8f5

URL: https://github.com/llvm/llvm-project/commit/0e9956204db3802ac94a7727bf2fe35c753cc8f5
DIFF: https://github.com/llvm/llvm-project/commit/0e9956204db3802ac94a7727bf2fe35c753cc8f5.diff

LOG: Revert "[JumpThreading] Preserve profile metadata during select unfolding"

This reverts commit 957952dbf2f34ed552e8e1f8c35eed17eee2ea38.

Addition in the newly added code can overflow.  As a result, the
constructor of `BranchProbability()` can trigger an assertion. See
the discussion on https://reviews.llvm.org/D138132 for more details.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/JumpThreading.cpp
    llvm/test/Transforms/JumpThreading/select.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 19ed7e555dc59..e9bf66c4c6974 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -2785,24 +2785,8 @@ void JumpThreadingPass::unfoldSelectInstr(BasicBlock *Pred, BasicBlock *BB,
   // Create a conditional branch and update PHI nodes.
   auto *BI = BranchInst::Create(NewBB, BB, SI->getCondition(), Pred);
   BI->applyMergedLocation(PredTerm->getDebugLoc(), SI->getDebugLoc());
-  BI->copyMetadata(*SI, {LLVMContext::MD_prof});
   SIUse->setIncomingValue(Idx, SI->getFalseValue());
   SIUse->addIncoming(SI->getTrueValue(), NewBB);
-  // Set the block frequency of NewBB.
-  if (HasProfileData) {
-    uint64_t TrueWeight, FalseWeight;
-    if (extractBranchWeights(*SI, TrueWeight, FalseWeight) &&
-        (TrueWeight + FalseWeight) != 0) {
-      SmallVector<BranchProbability, 2> BP;
-      BP.emplace_back(BranchProbability(TrueWeight, TrueWeight + FalseWeight));
-      BP.emplace_back(BranchProbability(FalseWeight, TrueWeight + FalseWeight));
-      BPI->setEdgeProbability(Pred, BP);
-    }
-
-    auto NewBBFreq =
-        BFI->getBlockFreq(Pred) * BPI->getEdgeProbability(Pred, NewBB);
-    BFI->setBlockFreq(NewBB, NewBBFreq.getFrequency());
-  }
 
   // The select is now dead.
   SI->eraseFromParent();

diff  --git a/llvm/test/Transforms/JumpThreading/select.ll b/llvm/test/Transforms/JumpThreading/select.ll
index d85fb45be5ff7..aedfab851d5d5 100644
--- a/llvm/test/Transforms/JumpThreading/select.ll
+++ b/llvm/test/Transforms/JumpThreading/select.ll
@@ -1,13 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -passes=jump-threading -debug-only=branch-prob < %s 2>&1 | FileCheck %s
-; REQUIRES: asserts
-
-; CHECK-LABEL:  ---- Branch Probability Info : unfold1 ----
-; CHECK:       set edge cond.false -> 0 successor probability to 0x0ccccccd / 0x80000000 = 10.00%
-; CHECK:       set edge cond.false -> 1 successor probability to 0x73333333 / 0x80000000 = 90.00%
-; CHECK-LABEL:  ---- Branch Probability Info : unfold2 ----
-; CHECK:       set edge cond.false -> 0 successor probability to 0x0ccccccd / 0x80000000 = 10.00%
-; CHECK:       set edge cond.false -> 1 successor probability to 0x73333333 / 0x80000000 = 90.00%
+; RUN: opt -S -passes=jump-threading < %s | FileCheck %s
 
 declare void @foo()
 declare void @bar()
@@ -273,7 +265,7 @@ L4:
   ret void
 }
 
-define void @unfold1(double %x, double %y) nounwind !prof !1 {
+define void @unfold1(double %x, double %y) nounwind {
 ; CHECK-LABEL: @unfold1(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[SUB:%.*]] = fsub double [[X:%.*]], [[Y:%.*]]
@@ -282,7 +274,7 @@ define void @unfold1(double %x, double %y) nounwind !prof !1 {
 ; CHECK:       cond.false:
 ; CHECK-NEXT:    [[ADD:%.*]] = fadd double [[X]], [[Y]]
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ogt double [[ADD]], 1.000000e+01
-; CHECK-NEXT:    br i1 [[CMP1]], label [[COND_END4]], label [[IF_THEN:%.*]], !prof [[PROF1:![0-9]+]]
+; CHECK-NEXT:    br i1 [[CMP1]], label [[COND_END4]], label [[IF_THEN:%.*]]
 ; CHECK:       cond.end4:
 ; CHECK-NEXT:    [[COND5:%.*]] = phi double [ [[SUB]], [[ENTRY:%.*]] ], [ [[ADD]], [[COND_FALSE]] ]
 ; CHECK-NEXT:    [[CMP6:%.*]] = fcmp oeq double [[COND5]], 0.000000e+00
@@ -301,7 +293,7 @@ entry:
 cond.false:                                       ; preds = %entry
   %add = fadd double %x, %y
   %cmp1 = fcmp ogt double %add, 1.000000e+01
-  %add. = select i1 %cmp1, double %add, double 0.000000e+00, !prof !0
+  %add. = select i1 %cmp1, double %add, double 0.000000e+00
   br label %cond.end4
 
 cond.end4:                                        ; preds = %entry, %cond.false
@@ -319,7 +311,7 @@ if.end:                                           ; preds = %if.then, %cond.end4
 }
 
 
-define void @unfold2(i32 %x, i32 %y) nounwind !prof !1 {
+define void @unfold2(i32 %x, i32 %y) nounwind {
 ; CHECK-LABEL: @unfold2(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[SUB:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
@@ -328,7 +320,7 @@ define void @unfold2(i32 %x, i32 %y) nounwind !prof !1 {
 ; CHECK:       cond.false:
 ; CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[X]], [[Y]]
 ; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[ADD]], 10
-; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[COND_END4:%.*]], !prof [[PROF1:![0-9]+]]
+; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[COND_END4:%.*]]
 ; CHECK:       cond.end4:
 ; CHECK-NEXT:    [[COND5:%.*]] = phi i32 [ [[ADD]], [[COND_FALSE]] ]
 ; CHECK-NEXT:    [[CMP6:%.*]] = icmp eq i32 [[COND5]], 0
@@ -347,7 +339,7 @@ entry:
 cond.false:                                       ; preds = %entry
   %add = add nsw i32 %x, %y
   %cmp1 = icmp sgt i32 %add, 10
-  %add. = select i1 %cmp1, i32 0, i32 %add, !prof !0
+  %add. = select i1 %cmp1, i32 0, i32 %add
   br label %cond.end4
 
 cond.end4:                                        ; preds = %entry, %cond.false
@@ -660,6 +652,3 @@ if.end:
   %v1 = select i1 %v, i32 %s, i32 42
   ret i32 %v1
 }
-
-!0 = !{!"branch_weights", i32 1, i32 9}
-!1 = !{!"function_entry_count", i64 1984}


        


More information about the llvm-commits mailing list