[llvm] [SimplifyCFG] Add optimization for switches of powers of two (PR #70977)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 17 10:15:51 PST 2023
================
@@ -6839,6 +6836,81 @@ static bool ReduceSwitchRange(SwitchInst *SI, IRBuilder<> &Builder,
return true;
}
+/// Tries to transform switch of powers of two to reduce switch range.
+/// For example, switch like:
+/// switch (C) { case 1: case 2: case 64: case 128: }
+/// will be transformed to:
+/// switch ( count_trailing_zeros(C) ) { case 0: case 1: case 6: case 7: }
+///
+/// This transformation allows better lowering and could allow transforming into
+/// a lookup table.
+static bool simplifySwitchOfPowersOfTwo(SwitchInst *SI, IRBuilder<> &Builder,
+ const DataLayout &DL,
+ const TargetTransformInfo &TTI) {
+
----------------
nikic wrote:
Unnecessary newline.
https://github.com/llvm/llvm-project/pull/70977
More information about the llvm-commits
mailing list