[PATCH] D21291: [SimplifyCFG] Range reduce switches

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 14:28:44 PDT 2016


sanjoy added a comment.

Haven't done a thorough review yet, but some minor nitpicky comments inline.


================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:5029
@@ +5028,3 @@
+  for (auto &V : Values)
+    GCD = llvm::GreatestCommonDivisor64(GCD, (uint64_t)V);
+  if (GCD <= 1 || !llvm::isPowerOf2_64(GCD))
----------------
This gcd computation looks like extra work -- why not:

```
uint64_t PotentialGCD = Values[1];
if (!isPowerOf2(PotentialGCD)) return false;
if (!all_of(Values, [](uint64_t V) { return V & (PotentialGCD - 1) == 0; }) return false;
```


================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:5072
@@ +5071,3 @@
+    auto *New = ConstantInt::get(Ty, Sub.lshr(APInt(BW, Shift)));
+    SI->replaceUsesOfWith(Orig, New);
+  }
----------------
This linear search (via `replaceUsesOfWith`) seems wasteful.  Why not change `getCaseValue` to  return a `Use &` and do `C.getCaseValue().set(New)` or something similar?


Repository:
  rL LLVM

http://reviews.llvm.org/D21291





More information about the llvm-commits mailing list