aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorEvandro Menezes <e.menezes@samsung.com>2019-04-30 18:35:38 +0000
committerEvandro Menezes <e.menezes@samsung.com>2019-04-30 18:35:38 +0000
commitea349f3ef592c053272ff0053c60eca704028e6e (patch)
tree236936554bb407ec08fd25ac7a36c6bfd1eaa77c /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
parent44697012070c6109d1f45422eb219c1b4d7c28a5 (diff)
downloadllvm-ea349f3ef592c053272ff0053c60eca704028e6e.zip
llvm-ea349f3ef592c053272ff0053c60eca704028e6e.tar.gz
llvm-ea349f3ef592c053272ff0053c60eca704028e6e.tar.bz2
[SimplifyLibCalls] Clean up code (NFC)
Fix pointer check after dereferencing (PR41665). llvm-svn: 359595
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 23b88db..0751078 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1059,7 +1059,7 @@ static Value *valueHasFloatPrecision(Value *Val) {
/// Shrink double -> float functions.
static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
bool isBinary, bool isPrecise = false) {
- if (!CI->getType()->isDoubleTy())
+ if (!CI->getType()->isDoubleTy() || !CI->getCalledFunction())
return nullptr;
// If not all the uses of the function are converted to float, then bail out.
@@ -1079,15 +1079,17 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
if (!V[0] || (isBinary && !V[1]))
return nullptr;
+ Function *CalleeFn = CI->getCalledFunction();
+ StringRef CalleeNm = CalleeFn->getName();
+ AttributeList CalleeAt = CalleeFn->getAttributes();
+ bool CalleeIn = CalleeFn->isIntrinsic();
+
// If call isn't an intrinsic, check that it isn't within a function with the
// same name as the float version of this call, otherwise the result is an
// infinite loop. For example, from MinGW-w64:
//
// float expf(float val) { return (float) exp((double) val); }
- Function *CalleeFn = CI->getCalledFunction();
- StringRef CalleeNm = CalleeFn->getName();
- AttributeList CalleeAt = CalleeFn->getAttributes();
- if (CalleeFn && !CalleeFn->isIntrinsic()) {
+ if (!CalleeIn) {
const Function *Fn = CI->getFunction();
StringRef FnName = Fn->getName();
if (FnName.back() == 'f' &&
@@ -1102,7 +1104,7 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
// g((double) float) -> (double) gf(float)
Value *R;
- if (CalleeFn->isIntrinsic()) {
+ if (CalleeIn) {
Module *M = CI->getModule();
Intrinsic::ID IID = CalleeFn->getIntrinsicID();
Function *Fn = Intrinsic::getDeclaration(M, IID, B.getFloatTy());