forked from OSchip/llvm-project
[ConstantFolding] avoid crashing on a fake math library call
https://llvm.org/PR50960
This commit is contained in:
parent
b43e083bb6
commit
13302c06cd
|
@ -3041,10 +3041,18 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (!F->hasName())
|
if (!F->hasName())
|
||||||
return nullptr;
|
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();
|
StringRef Name = F->getName();
|
||||||
|
|
||||||
Type *Ty = F->getReturnType();
|
Type *Ty = F->getReturnType();
|
||||||
|
|
||||||
if (auto *FVTy = dyn_cast<FixedVectorType>(Ty))
|
if (auto *FVTy = dyn_cast<FixedVectorType>(Ty))
|
||||||
return ConstantFoldFixedVectorCall(
|
return ConstantFoldFixedVectorCall(
|
||||||
Name, F->getIntrinsicID(), FVTy, Operands,
|
Name, F->getIntrinsicID(), FVTy, Operands,
|
||||||
|
@ -3055,6 +3063,9 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F,
|
||||||
Name, F->getIntrinsicID(), SVTy, Operands,
|
Name, F->getIntrinsicID(), SVTy, Operands,
|
||||||
F->getParent()->getDataLayout(), TLI, Call);
|
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,
|
return ConstantFoldScalarCall(Name, F->getIntrinsicID(), Ty, Operands, TLI,
|
||||||
Call);
|
Call);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue