[PATCH] D13994: [SimplifyLibCalls] Optimization for pow(x, n) where n is some constant

Chad Rosier via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 06:16:01 PST 2015


mcrosier added inline comments.

================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1101
@@ +1100,3 @@
+  AddChain[32] = B.CreateFMul(AddChain[16], AddChain[16]);
+  return AddChain[Exp];
+}
----------------
I believe the point David is trying to make is that you don't need to compute all 32 chains (at compile-time) when exp is less than 32.

How about something like this:
  static const unsigned ExpTable[32][2] = {
    { 0, 0 }, // Unused
    { 0, 0 }, // pow1
    { 0, 0 }, // pow1, pow1
    { 1, 2 }, // 
    { 2, 2 },
    { 2, 3 },
    { 3, 3 },
    { 2, 5 },
    { 4, 4 },
    { 1, 8 },
       ...
    { 16, 16 } }

if (exp == 1)
  return pow1;

if (exp == 2)
  return B.CreateFMul(pow1, pow1);

AddChain[1] = pow1;
AddChain[2] = B.CreateFMul(pow1, pow1);
for (unsigned i = 3; i < exp; ++i)
  AddChain[i] = B.CreateFMul(AddChain[ExpTable[i][0]], AddChain[ExpTable[i][1]]);

return AddChain[exp];


http://reviews.llvm.org/D13994





More information about the llvm-commits mailing list