[llvm] SimplifyCFG: Enable switch replacements in more cases (PR #156477)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 4 08:02:42 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.
----------------
nikic wrote:
Based on the llvm-opt-benchmark results, we should also guard BitMapKind behind ConvertSwitchToLookupTable. Similar to lookup tables, this representation may make further optimization harder.
(I'd also be okay with dropping the ConvertSwitchToLookupTable change from this PR to not block the rest of the changes on flushing out all the phase ordering issues.)
https://github.com/llvm/llvm-project/pull/156477
More information about the llvm-commits
mailing list