[llvm] SimplifyCFG: Enable switch replacements in more cases (PR #156477)

Jessica Del via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 5 05:38:37 PDT 2025


================
@@ -7086,6 +7087,26 @@ static bool simplifySwitchLookup(SwitchInst *SI, IRBuilder<> &Builder,
     PhiToReplacementMap.insert({PHI, Replacement});
   }
 
+  bool AnyLookupTables = any_of(
+      PhiToReplacementMap, [](auto &KV) { return KV.second.isLookupTable(); });
+
+  // A few conditions prevent the generation of lookup tables:
+  //     1. Not setting the ConvertSwitchToLookupTable option
+  //        This option prevents the LUT creation until a later stage in the
+  //        pipeline, because it would otherwise result in some
+  //        difficult-to-analyze code and make pruning branches much harder.
+  //        This is a problem if the switch expression itself can be restricted
+  //        by inlining or CVP.
----------------
OutOfCache wrote:

Thanks for looking into the benchmark and reviewing. I decided to guard the bitmap creation with ConvertSwitchToLookup for now instead of completely removing the ConvertSwitchToLookup change. Hopefully the new benchmark results will show no other regressions, so the other kinds of transformations can still be applied earlier without issues, otherwise I will remove it for now.

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


More information about the llvm-commits mailing list