From 7afcace1cd874d12807f08790894e01ce6f956fa Mon Sep 17 00:00:00 2001 From: Guozhi Wei Date: Wed, 4 Oct 2017 20:14:08 +0000 Subject: [PATCH] [TargetTransformInfo] Check if function pointer is valid before calling isLoweredToCall Function isLoweredToCall can only accept non-null function pointer, but a function pointer can be null for indirect function call. So check it before calling isLoweredToCall from getInstructionLatency. Differential Revision: https://reviews.llvm.org/D38204 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314927 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/TargetTransformInfoImpl.h | 4 +++- test/Analysis/CostModel/X86/costmodel.ll | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/llvm/Analysis/TargetTransformInfoImpl.h b/include/llvm/Analysis/TargetTransformInfoImpl.h index 5819b2eb9f4..2434f593bbb 100644 --- a/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -188,6 +188,8 @@ public: } bool isLoweredToCall(const Function *F) { + assert(F && "A concrete function must be provided to this routine."); + // FIXME: These should almost certainly not be handled here, and instead // handled with the help of TLI or the target itself. This was largely // ported from existing analysis heuristics here so that such refactorings @@ -828,7 +830,7 @@ public: // A real function call is much slower. if (auto *CI = dyn_cast(I)) { const Function *F = CI->getCalledFunction(); - if (static_cast(this)->isLoweredToCall(F)) + if (!F || static_cast(this)->isLoweredToCall(F)) return 40; // Some intrinsics return a value and a flag, we use the value type // to decide its latency. diff --git a/test/Analysis/CostModel/X86/costmodel.ll b/test/Analysis/CostModel/X86/costmodel.ll index 19e7128ff44..246dc12eb59 100644 --- a/test/Analysis/CostModel/X86/costmodel.ll +++ b/test/Analysis/CostModel/X86/costmodel.ll @@ -45,6 +45,10 @@ define i64 @foo(i64 %arg) { ; CODESIZE: cost of 1 {{.*}} call %uadd = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 undef, i32 undef) + ; LATENCY: cost of 40 {{.*}} call void undef + ; CODESIZE: cost of 1 {{.*}} call void undef + call void undef() + ; LATENCY: cost of 1 {{.*}} ret ; CODESIZE: cost of 1 {{.*}} ret ret i64 undef -- 2.50.1