[llvm-branch-commits] [llvm] fd15003 - Revert "[SimplifyCFG] Mark branch weights unknown in masked switch to lookup …"
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Oct 18 18:46:42 PDT 2026
Author: Aiden Grossman
Date: 2026-10-18T18:46:37-07:00
New Revision: fd150034b6bad04a48066853c860f950dcfab0f5
URL: https://github.com/llvm/llvm-project/commit/fd150034b6bad04a48066853c860f950dcfab0f5
DIFF: https://github.com/llvm/llvm-project/commit/fd150034b6bad04a48066853c860f950dcfab0f5.diff
LOG: Revert "[SimplifyCFG] Mark branch weights unknown in masked switch to lookup …"
This reverts commit 299c65b98b0248d0dabf19f0c5126b69eae7f7e4.
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Removed:
llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-masked-profile.ll
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index ace681ea9d81d1..1ac9bd15dbb08d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -7802,9 +7802,7 @@ static bool simplifySwitchLookup(SwitchInst *SI, IRBuilder<> &Builder,
Builder.SetInsertPoint(SI);
const bool GeneratingCoveredLookupTable = (MaxTableSize == TableSize);
- const bool IsFullyCoveredLookupTable =
- !DefaultIsReachable || GeneratingCoveredLookupTable;
- if (IsFullyCoveredLookupTable) {
+ if (!DefaultIsReachable || GeneratingCoveredLookupTable) {
Builder.CreateBr(LookupBB);
if (DTU)
Updates.push_back({DominatorTree::Insert, BB, LookupBB});
@@ -7854,8 +7852,6 @@ static bool simplifySwitchLookup(SwitchInst *SI, IRBuilder<> &Builder,
Value *Shifted = Builder.CreateLShr(TableMask, MaskIndex, "switch.shifted");
Value *LoBit = Builder.CreateTrunc(
Shifted, Type::getInt1Ty(Mod.getContext()), "switch.lobit");
- if (!IsFullyCoveredLookupTable)
- setExplicitlyUnknownBranchWeightsIfProfiled(*CondBranch, DEBUG_TYPE);
CondBranch = Builder.CreateCondBr(LoBit, LookupBB, SI->getDefaultDest());
if (DTU) {
Updates.push_back({DominatorTree::Insert, MaskBB, LookupBB});
@@ -7919,14 +7915,7 @@ static bool simplifySwitchLookup(SwitchInst *SI, IRBuilder<> &Builder,
ToLookupWeight += BranchWeights[I];
}
SI->eraseFromParent();
- // In the case where we do not have a fully covered lookup table (i.e., we
- // need a range check), and we need a mask check, we split the default case
- // into two
diff erent cases for which we cannot infer branch weights.
- // Otherwise we have a single branch for which we can infer branch weights.
- if ((NeedMask && !IsFullyCoveredLookupTable) &&
- !ProfcheckDisableMetadataFixes)
- setExplicitlyUnknownBranchWeightsIfProfiled(*CondBranch, DEBUG_TYPE);
- else if (HasBranchWeights)
+ if (HasBranchWeights)
setFittedBranchWeights(*CondBranch, {ToLookupWeight, ToDefaultWeight},
/*IsExpected=*/false);
if (DTU)
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-masked-profile.ll b/llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-masked-profile.ll
deleted file mode 100644
index 93a85cbc5170f6..00000000000000
--- a/llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-masked-profile.ll
+++ /dev/null
@@ -1,48 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
-; RUN: opt < %s -passes="simplifycfg<switch-to-lookup>" -S | FileCheck %s
-
-target triple = "x86_64-unknown-linux-gnu"
-
-; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
-define i16 @four_out_of_fifteen(ptr %this, i8 %0) !prof !0 {
-; CHECK-LABEL: define i16 @four_out_of_fifteen(
-; CHECK-SAME: ptr [[THIS:%.*]], i8 [[TMP0:%.*]]) !prof [[PROF0:![0-9]+]] {
-; CHECK-NEXT: [[ENTRY:.*:]]
-; CHECK-NEXT: [[SWITCH_TABLEIDX:%.*]] = sub i8 [[TMP0]], 57
-; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[SWITCH_TABLEIDX]], 11
-; CHECK-NEXT: br i1 [[TMP1]], label %[[SWITCH_HOLE_CHECK:.*]], label %[[SW_EPILOG66:.*]], !prof [[PROF1:![0-9]+]]
-; CHECK: [[SWITCH_HOLE_CHECK]]:
-; CHECK-NEXT: [[SWITCH_MASKINDEX:%.*]] = zext i8 [[SWITCH_TABLEIDX]] to i16
-; CHECK-NEXT: [[SWITCH_SHIFTED:%.*]] = lshr i16 1793, [[SWITCH_MASKINDEX]]
-; CHECK-NEXT: [[SWITCH_LOBIT:%.*]] = trunc i16 [[SWITCH_SHIFTED]] to i1
-; CHECK-NEXT: br i1 [[SWITCH_LOBIT]], label %[[COMMON_RET:.*]], label %[[SW_EPILOG66]], !prof [[PROF1]]
-; CHECK: [[COMMON_RET]]:
-; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i16 [ 0, %[[SW_EPILOG66]] ], [ 1, %[[SWITCH_HOLE_CHECK]] ]
-; CHECK-NEXT: ret i16 [[COMMON_RET_OP]]
-; CHECK: [[SW_EPILOG66]]:
-; CHECK-NEXT: store i8 0, ptr [[THIS]], align 8
-; CHECK-NEXT: br label %[[COMMON_RET]]
-;
-entry:
- switch i8 %0, label %sw.epilog66 [
- i8 57, label %common.ret
- i8 65, label %common.ret
- i8 66, label %common.ret
- i8 67, label %common.ret
- ], !prof !1
-
-common.ret:
- %common.ret.op = phi i16 [ 0, %sw.epilog66 ], [ 1, %entry ], [ 1, %entry ], [ 1, %entry ], [ 1, %entry ]
- ret i16 %common.ret.op
-
-sw.epilog66:
- store i8 0, ptr %this, align 8
- br label %common.ret
-}
-
-!0 = !{!"function_entry_count", i64 62163}
-!1 = !{!"branch_weights", i32 19796, i32 1297434962, i32 18771, i32 4410451, i32 4}
-;.
-; CHECK: [[PROF0]] = !{!"function_entry_count", i64 62163}
-; CHECK: [[PROF1]] = !{!"unknown", !"simplifycfg"}
-;.
More information about the llvm-branch-commits
mailing list