[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: }
----------------
nikic wrote:

```suggestion
/// switch (count_trailing_zeros(C)) { case 0: case 1: case 6: case 7: }
```

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


More information about the llvm-commits mailing list