1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[SimplifyLibCalls] fix crash with empty function name (PR43347)

...and improve some variable names while here.

https://bugs.llvm.org/show_bug.cgi?id=43347

llvm-svn: 372227
This commit is contained in:
Sanjay Patel 2019-09-18 14:33:40 +00:00
parent 5dc924b7ff
commit 07efb26652
2 changed files with 24 additions and 15 deletions

View File

@ -1258,21 +1258,18 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
if (!V[0] || (isBinary && !V[1])) if (!V[0] || (isBinary && !V[1]))
return nullptr; return nullptr;
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 // 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 // same name as the float version of this call, otherwise the result is an
// infinite loop. For example, from MinGW-w64: // infinite loop. For example, from MinGW-w64:
// //
// float expf(float val) { return (float) exp((double) val); } // float expf(float val) { return (float) exp((double) val); }
if (!CalleeIn) { StringRef CalleeName = CalleeFn->getName();
const Function *Fn = CI->getFunction(); bool IsIntrinsic = CalleeFn->isIntrinsic();
StringRef FnName = Fn->getName(); if (!IsIntrinsic) {
if (FnName.back() == 'f' && StringRef CallerName = CI->getFunction()->getName();
FnName.size() == (CalleeNm.size() + 1) && if (!CallerName.empty() && CallerName.back() == 'f' &&
FnName.startswith(CalleeNm)) CallerName.size() == (CalleeName.size() + 1) &&
CallerName.startswith(CalleeName))
return nullptr; return nullptr;
} }
@ -1282,16 +1279,16 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
// g((double) float) -> (double) gf(float) // g((double) float) -> (double) gf(float)
Value *R; Value *R;
if (CalleeIn) { if (IsIntrinsic) {
Module *M = CI->getModule(); Module *M = CI->getModule();
Intrinsic::ID IID = CalleeFn->getIntrinsicID(); Intrinsic::ID IID = CalleeFn->getIntrinsicID();
Function *Fn = Intrinsic::getDeclaration(M, IID, B.getFloatTy()); Function *Fn = Intrinsic::getDeclaration(M, IID, B.getFloatTy());
R = isBinary ? B.CreateCall(Fn, V) : B.CreateCall(Fn, V[0]); R = isBinary ? B.CreateCall(Fn, V) : B.CreateCall(Fn, V[0]);
} else {
AttributeList CalleeAttrs = CalleeFn->getAttributes();
R = isBinary ? emitBinaryFloatFnCall(V[0], V[1], CalleeName, B, CalleeAttrs)
: emitUnaryFloatFnCall(V[0], CalleeName, B, CalleeAttrs);
} }
else
R = isBinary ? emitBinaryFloatFnCall(V[0], V[1], CalleeNm, B, CalleeAt)
: emitUnaryFloatFnCall(V[0], CalleeNm, B, CalleeAt);
return B.CreateFPExt(R, B.getDoubleTy()); return B.CreateFPExt(R, B.getDoubleTy());
} }

View File

@ -47,5 +47,17 @@ define float @test3(float* %v) nounwind uwtable ssp {
ret float %conv38 ret float %conv38
} }
; PR43347 - https://bugs.llvm.org/show_bug.cgi?id=43347
define void @0(float %f) {
; CHECK-LABEL: @0(
; CHECK-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[F:%.*]]) #2
; CHECK-NEXT: ret void
;
%d = fpext float %f to double
%r = call double @sqrt(double %d)
ret void
}
declare i32 @foo(double) declare i32 @foo(double)
declare double @sqrt(double) readnone declare double @sqrt(double) readnone