[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 17:57:49 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();
----------------
scanon wrote:
> 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().
With r253254, I think you should be able to make this general pretty easily.  Something like:

```
APFloat V = abs(Op2C->getValueAPF( ));
if ((V.compare(APFloat(32.0)) == APFloat::cmpGreaterThan) || !V.isInteger())
    return nullptr;
// V is known to be an integer in [0, 32], so it can safely be converted to double now
// int would be even nicer, but APFloat doesn't have convertToInt (yet?). 
Value *FMul = getPow(Op1, convertToDouble(V), B);
```


http://reviews.llvm.org/D13994





More information about the llvm-commits mailing list