[llvm] [SwitchLowering] Support merging 0 and power-of-2 case. (PR #139736)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu May 29 00:49:37 PDT 2025
================
@@ -362,6 +362,41 @@ void SwitchCG::SwitchLowering::findBitTestClusters(CaseClusterVector &Clusters,
}
}
Clusters.resize(DstIndex);
+
+ // Check if the clusters contain one checking for 0 and another one checking
+ // for a power-of-2 constant with matching destinations. Those clusters can be
+ // combined to a single ane with CC_And.
+ unsigned ZeroIdx = -1;
+ for (const auto &[Idx, C] : enumerate(Clusters)) {
+ if (C.Kind != CC_Range || C.Low != C.High)
+ continue;
+ if (C.Low->isZero()) {
+ ZeroIdx = Idx;
+ break;
+ }
+ }
+ if (ZeroIdx == -1u)
+ return;
+
+ unsigned Pow2Idx = -1;
+ for (const auto &[Idx, C] : enumerate(Clusters)) {
----------------
jayfoad wrote:
Oh I see, there could be many power of two values, but you need to find one with the same MBB destination.
https://github.com/llvm/llvm-project/pull/139736
More information about the llvm-commits
mailing list