[PATCH] D21291: [SimplifyCFG] Range reduce switches

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 13:59:40 PDT 2016


eli.friedman added inline comments.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:5022
@@ +5021,3 @@
+  for (auto &V : Values)
+    V -= Base;
+
----------------
Nit: please make the implicit casting here explicit.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:5031
@@ +5030,3 @@
+  if (GCD <= 1 || !llvm::isPowerOf2_64(GCD))
+    // We refuse to output a costly urem/udiv pair.
+    return false;
----------------
If the GCD is some odd number N, you can multiply by the inverse of N and switch on that.  Not sure if that's actually useful in practice.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:5056
@@ +5055,3 @@
+  OldBB->getTerminator()->eraseFromParent();
+  BranchInst::Create(SI->getParent(), SI->getDefaultDest(), Cmp, OldBB);
+
----------------
If we were doing this in SelectionDAG, we would be able to combine this branch with the jump table's bounds check: "ROTATE(X - Base, Shift) > Limit".


Repository:
  rL LLVM

http://reviews.llvm.org/D21291





More information about the llvm-commits mailing list