1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[ConstantFolding] avoid crashing on a fake math library call

https://llvm.org/PR50960
This commit is contained in:
Sanjay Patel 2021-07-20 18:23:20 -04:00
parent a36faebe1f
commit cc2611c224
2 changed files with 28 additions and 2 deletions

View File

@ -3041,10 +3041,18 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F,
return nullptr;
if (!F->hasName())
return nullptr;
// If this is not an intrinsic and not recognized as a library call, bail out.
if (F->getIntrinsicID() == Intrinsic::not_intrinsic) {
if (!TLI)
return nullptr;
LibFunc LibF;
if (!TLI->getLibFunc(*F, LibF))
return nullptr;
}
StringRef Name = F->getName();
Type *Ty = F->getReturnType();
if (auto *FVTy = dyn_cast<FixedVectorType>(Ty))
return ConstantFoldFixedVectorCall(
Name, F->getIntrinsicID(), FVTy, Operands,
@ -3055,6 +3063,9 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F,
Name, F->getIntrinsicID(), SVTy, Operands,
F->getParent()->getDataLayout(), TLI, Call);
// TODO: If this is a library function, we already discovered that above,
// so we should pass the LibFunc, not the name (and it might be better
// still to separate intrinsic handling from libcalls).
return ConstantFoldScalarCall(Name, F->getIntrinsicID(), Ty, Operands, TLI,
Call);
}

View File

@ -0,0 +1,15 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
; This is not the mathlib call you were looking for.
declare double @sin(x86_fp80)
define double @PR50960(x86_fp80 %0) {
; CHECK-LABEL: @PR50960(
; CHECK-NEXT: [[CALL:%.*]] = call double @sin(x86_fp80 0xK3FFF8000000000000000)
; CHECK-NEXT: ret double [[CALL]]
;
%call = call double @sin(x86_fp80 0xK3FFF8000000000000000)
ret double %call
}