[llvm] [SelectionDAG] Avoid redundant comparisons in bit-test switch lowering (PR #222626)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 13:51:15 PDT 2026


================
@@ -12536,20 +12534,45 @@ void SelectionDAGBuilder::lowerWorkItem(SwitchWorkListItem W, Value *Cond,
   for (CaseClusterIt I = W.FirstCluster; I <= W.LastCluster; ++I)
     UnhandledProbs += I->Prob;
 
-  MachineBasicBlock *CurMBB = W.MBB;
-  for (CaseClusterIt I = W.FirstCluster, E = W.LastCluster; I <= E; ++I) {
+  // Insert bit-test blocks before the linear work-item continuation blocks so
+  // that pre-creating the latter preserves the existing layout.
+  for (CaseClusterIt I = W.FirstCluster; I <= W.LastCluster; ++I) {
+    if (I->Kind != CC_BitTests)
+      continue;
+    BitTestBlock *BTB = &SL->BitTestCases[I->BTCasesIndex];
----------------
topperc wrote:

Can this be a reference instead of a pointer?

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


More information about the llvm-commits mailing list