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

Steve Canon via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 30 06:53:18 PDT 2015


scanon added inline comments.

================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1156
@@ +1155,3 @@
+      for (unsigned Exp = 2; Exp <= 32; ++Exp) {
+        if (Op2C->isExactlyValue(Exp) || Op2C->isExactlyValue((int)-Exp)) {
+          Value *FMul = getPow(Op1, Exp, B);
----------------
Can we really not find a more elegant way to handle this than by checking for equality to every integer in range?  How was 32 chosen?  It would make more sense to bound the number of multiplies in the resulting lowering than bounding the magnitude of the exponent.  I would also expect this to not be symmetric, because division is expensive.

================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1158
@@ +1157,3 @@
+          Value *FMul = getPow(Op1, Exp, B);
+          // For negative exponents simply divide by 1.0.
+          if (Op2C->isExactlyValue((int)-Exp))
----------------
s/divide by 1.0/compute the reciprocal/


Repository:
  rL LLVM

http://reviews.llvm.org/D13994





More information about the llvm-commits mailing list