summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-01-20 17:41:14 +0000
committerSanjay Patel <spatel@rotateright.com>2016-01-20 17:41:14 +0000
commitbd2dc67142a1861b89e8a9752f9fb407afcf7b07 (patch)
tree23b9eb64dd724c30a6f18d2f128af0686bc42c58 /llvm/lib
parent6c3e790e788fea0b9a40f62995c87a14f48f2e02 (diff)
downloadbcm5719-llvm-bd2dc67142a1861b89e8a9752f9fb407afcf7b07.tar.gz
bcm5719-llvm-bd2dc67142a1861b89e8a9752f9fb407afcf7b07.zip
[LibCallSimplifier] don't get fooled by a fake sqrt()
The test case will crash without this patch because the subsequent call to hasUnsafeAlgebra() assumes that the call instruction is an FPMathOperator (ie, returns an FP type). This part of the function signature check was omitted for the sqrt() case, but seems to be in place for all other transforms. Before: http://reviews.llvm.org/rL257400 ...we would have needlessly continued execution in optimizeSqrt(), but the bug was harmless because we'd eventually fail some other check and return without damage. This should fix: https://llvm.org/bugs/show_bug.cgi?id=26211 Differential Revision: http://reviews.llvm.org/D16198 llvm-svn: 258325
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 26f3b7b38e5..079159b8215 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1376,12 +1376,21 @@ Value *LibCallSimplifier::optimizeLog(CallInst *CI, IRBuilder<> &B) {
Value *LibCallSimplifier::optimizeSqrt(CallInst *CI, IRBuilder<> &B) {
Function *Callee = CI->getCalledFunction();
-
+
Value *Ret = nullptr;
if (TLI->has(LibFunc::sqrtf) && (Callee->getName() == "sqrt" ||
Callee->getIntrinsicID() == Intrinsic::sqrt))
Ret = optimizeUnaryDoubleFP(CI, B, true);
+ // FIXME: Refactor - this check is repeated all over this file and even in the
+ // preceding call to shrink double -> float.
+
+ // Make sure this has 1 argument of FP type, which matches the result type.
+ FunctionType *FT = Callee->getFunctionType();
+ if (FT->getNumParams() != 1 || FT->getReturnType() != FT->getParamType(0) ||
+ !FT->getParamType(0)->isFloatingPointTy())
+ return Ret;
+
if (!CI->hasUnsafeAlgebra())
return Ret;
OpenPOWER on IntegriCloud