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

Steve Canon via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 12:27:28 PST 2015


scanon added inline comments.

================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1210
@@ +1209,3 @@
+    Type *Ty = Op2C->getType();
+    double V = Ty->isFloatTy() ? Op2C->getValueAPF().convertToFloat() :
+                                 Op2C->getValueAPF().convertToDouble();
----------------
I think either this does the wrong thing for x86 80-bit long doubles (or does it not apply to powl( )?) and a hypothetical future quad type, or it could simply be Op2C->getValueAPF().convertToDouble().

================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1218
@@ +1217,3 @@
+    // Also, this transformation only applies to whole number exponents.
+    if (V > 32 || ceil(V) != floor(V))
+      return nullptr;
----------------
Super minor nit, ceil(V) != floor(V) is an overly-complex way to check if V is an integer.  trunc(V) != V is simpler and seems more idiomatic to me.  Longer-term, we should just add isInteger( ) to APFloat, but that's outside the scope of this change.


http://reviews.llvm.org/D13994





More information about the llvm-commits mailing list