[llvm] [SimplifyCFG] Simplify switch default branch when branch proves operand value (PR #206597)

Sayan Sivakumaran via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 5 08:34:20 PDT 2026


================
@@ -7813,6 +7813,42 @@ static bool simplifySwitchWhenUMin(SwitchInst *SI, DomTreeUpdater *DTU) {
   return true;
 }
 
+static bool simplifySwitchDefaultBranch(SwitchInst *SI, DomTreeUpdater *DTU,
+                                        const DataLayout &DL,
+                                        AssumptionCache *AC) {
+  assert(SI);
+  if (SI->defaultDestUnreachable())
+    return false;
+
+  // If it can be proved that the switch condition takes some concrete value
+  // in the default block, we can make some nice simplifications to the
+  // switch.
+  BasicBlock *Default = SI->getDefaultDest();
+  const Instruction *CxtI = Default->getTerminator();
----------------
sivakusayan wrote:

Thanks, I didn't think about that case. Presumably to handle things like `llvm.trap()` right? I'll take a look and add another test sometime today or tomorrow.

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


More information about the llvm-commits mailing list