[llvm-branch-commits] [llvm] release/22.x: [SimplifyCFG] process prof data when remove case in umin (#182261) (PR #185375)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Mar 9 01:42:19 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (llvmbot)

<details>
<summary>Changes</summary>

Backport 31e5f86a3cdc960ef7b2f0a533c4a37cf526cacd

Requested by: @<!-- -->nikic

---
Full diff: https://github.com/llvm/llvm-project/pull/185375.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+1-1) 
- (modified) llvm/test/Transforms/SimplifyCFG/switch-umin.ll (+43) 


``````````diff
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 5f4807242581d..a16f274a4ed5a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -7724,7 +7724,7 @@ static bool simplifySwitchWhenUMin(SwitchInst *SI, DomTreeUpdater *DTU) {
     BasicBlock *DeadCaseBB = I->getCaseSuccessor();
     DeadCaseBB->removePredecessor(BB);
     Updates.push_back({DominatorTree::Delete, BB, DeadCaseBB});
-    I = SIW->removeCase(I);
+    I = SIW.removeCase(I);
     E = SIW->case_end();
   }
 
diff --git a/llvm/test/Transforms/SimplifyCFG/switch-umin.ll b/llvm/test/Transforms/SimplifyCFG/switch-umin.ll
index 44665365dc222..ff958e4d04147 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-umin.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-umin.ll
@@ -239,8 +239,51 @@ case4:
 
 }
 
+define void @switch_remove_dead_cases(i32 %x) {
+; CHECK-LABEL: define void @switch_remove_dead_cases(
+; CHECK-SAME: i32 [[X:%.*]]) {
+; CHECK-NEXT:    [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[X]], i32 4)
+; CHECK-NEXT:    switch i32 [[X]], label %[[COMMON_RET:.*]] [
+; CHECK-NEXT:      i32 2, label %[[CASE_A:.*]]
+; CHECK-NEXT:      i32 3, label %[[CASE_B:.*]]
+; CHECK-NEXT:    ], !prof [[PROF1:![0-9]+]]
+; CHECK:       [[COMMON_RET]]:
+; CHECK-NEXT:    ret void
+; CHECK:       [[CASE_A]]:
+; CHECK-NEXT:    call void @a()
+; CHECK-NEXT:    br label %[[COMMON_RET]]
+; CHECK:       [[CASE_B]]:
+; CHECK-NEXT:    call void @b()
+; CHECK-NEXT:    br label %[[COMMON_RET]]
+;
+  %min = call i32 @llvm.umin.i32(i32 %x, i32 4)
+  switch i32 %min, label %unreachable [
+  i32 2, label %case_a
+  i32 3, label %case_b
+  i32 4, label %case_ret
+  i32 5, label %case_ret
+  ], !prof !1
+
+case_a:
+  call void @a()
+  ret void
+
+case_b:
+  call void @b()
+  ret void
+
+case_ret:
+  ret void
+
+unreachable:
+  unreachable
+}
 
 !0 = !{!"branch_weights", i32 1, i32 2, i32 3, i32 99, i32 5}
 ;.
 ; CHECK: [[PROF0]] = !{!"branch_weights", i32 5, i32 2, i32 3, i32 99}
 ;.
+!1 = !{!"branch_weights", i32 11, i32 12, i32 13, i32 14, i32 15}
+;.
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 14, i32 12, i32 13}
+;.

``````````

</details>


https://github.com/llvm/llvm-project/pull/185375


More information about the llvm-branch-commits mailing list