diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp index 2b50ccdc2eeb4..ce75f8eff6170 100644 --- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp +++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp @@ -56,6 +56,14 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc, // dst = phi(v0, v1) // + ORE->emit([&]() { + return OptimizationRemarkMissed(DEBUG_TYPE, "BranchInserted", + Call->getDebugLoc(), &CurrBB) + << "branch to library sqrt fn had to be inserted to satisfy the " + "current target's requirement for math functions to set errno on " + "invalid inputs"; + }); + Type *Ty = Call->getType(); IRBuilder<> Builder(Call->getNextNode()); @@ -125,11 +133,29 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI, if (!Call || !(CalledFunc = Call->getCalledFunction())) continue; - if (Call->isNoBuiltin() || Call->isStrictFP()) + if (Call->isNoBuiltin()) continue; - - if (Call->isMustTailCall()) + if (Call->isStrictFP()) { + ORE->emit([&]() { + return OptimizationRemarkMissed(DEBUG_TYPE, "StrictFloat", + Call->getDebugLoc(), &*CurrBB) + << "could not consider library function for partial inlining:" + " strict FP exception behavior is active"; + }); continue; + } + // Partially inlining a libcall that has the musttail attribute leads to + // broken LLVM IR, triggering an assertion in the IR verifier. + // Work around that by forgoing this optimization for musttail calls. + if (Call->isMustTailCall()) { + ORE->emit([&]() { + return OptimizationRemarkMissed(DEBUG_TYPE, "MustTailCall", + Call->getDebugLoc(), &*CurrBB) + << "could not consider library function for partial inlining:" + " must tail call"; + }); + continue; + } // Skip if function either has local linkage or is not a known library // function. @@ -143,8 +169,16 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI, case LibFunc_sqrt: if (TTI->haveFastSqrt(Call->getType()) && optimizeSQRT(Call, CalledFunc, *CurrBB, BB, TTI, - DTU ? &*DTU : nullptr, ORE)) + DTU ? &*DTU : nullptr, ORE)) { + ORE->emit([&]() { + return OptimizationRemark(DEBUG_TYPE, "SqrtPartiallyInlined", + Call->getDebugLoc(), &*CurrBB) + << "partially inlined call to sqrt function despite having " + "to use errno for error handling: target has fast sqrt " + "instruction"; + }); break; + } continue; default: continue; diff --git a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll index e6c2a7e629a5d..d6deb84994cdd 100644 --- a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll +++ b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll @@ -1,8 +1,12 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s +; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu -pass-remarks=partially-inline-libcalls \ +; RUN: -pass-remarks-missed=partially-inline-libcalls 2>%t < %s | FileCheck %s +; RUN: FileCheck %s -check-prefix=CHECK-REMARK --input-file=%t define float @f(float %val) { ; CHECK-LABEL: @f( +; CHECK-REMARK: partially inlined call to sqrt function despite having to use errno for error handling: target has fast sqrt instruction +; CHECK-REMARK: branch to library sqrt fn had to be inserted to satisfy the current target's requirement for math functions to set errno on invalid inputs ; CHECK-NEXT: entry: ; CHECK-NEXT: [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) #[[READNONE:.*]] ; CHECK-NEXT: [[TMP0:%.*]] = fcmp oge float [[VAL]], 0.000000e+00 diff --git a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll index 65dd616b43ea6..0d0075c04109e 100644 --- a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll +++ b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll @@ -1,8 +1,10 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s +; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu -pass-remarks-missed=partially-inline-libcalls 2>%t < %s | FileCheck %s +; RUN: FileCheck %s -check-prefix=CHECK-REMARK --input-file=%t define double @foo(double %x) { ; CHECK-LABEL: @foo( +; CHECK-REMARK: could not consider library function for partial inlining: must tail call ; CHECK-NEXT: [[R:%.*]] = musttail call double @sqrt(double [[X:%.*]]) ; CHECK-NEXT: ret double [[R]] ; diff --git a/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll index 8d18d1969b04d..e300e3874b715 100644 --- a/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll +++ b/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll @@ -1,7 +1,9 @@ -; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s +; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu -pass-remarks-missed=partially-inline-libcalls 2>%t < %s | FileCheck %s +; RUN: FileCheck %s -check-prefix=CHECK-REMARK --input-file=%t define float @f(float %val) strictfp { ; CHECK-LABEL: @f +; CHECK-REMARK: could not consider library function for partial inlining: strict FP exception behavior is active ; CHECK: call{{.*}}@sqrtf ; CHECK-NOT: call{{.*}}@sqrtf %res = tail call float @sqrtf(float %val) strictfp