[llvm] [WIP] Emit missed- and passed-optimization messages when partially inlining sqrt (PR #123966)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 23 06:52:22 PST 2025
https://github.com/TiborGY updated https://github.com/llvm/llvm-project/pull/123966
>From e8d7b204dce1c6a75285b83c2eba67e2310ab22b Mon Sep 17 00:00:00 2001
From: GYT <tiborgyri at gmail.com>
Date: Wed, 22 Jan 2025 17:52:25 +0100
Subject: [PATCH] test maybe
---
.../Scalar/PartiallyInlineLibCalls.cpp | 43 ++++++++++++++++---
.../X86/good-prototype.ll | 4 +-
.../PartiallyInlineLibCalls/strictfp.ll | 1 +
3 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index 2b50ccdc2eeb4f..caba5ce5777371 100644
--- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -56,6 +56,20 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
// dst = phi(v0, v1)
//
+ 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";
+ });
+ 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,18 +139,35 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
if (!Call || !(CalledFunc = Call->getCalledFunction()))
continue;
- if (Call->isNoBuiltin() || Call->isStrictFP())
- continue;
-
- if (Call->isMustTailCall())
- continue;
-
// Skip if function either has local linkage or is not a known library
// function.
LibFunc LF;
if (CalledFunc->hasLocalLinkage() ||
!TLI->getLibFunc(*CalledFunc, LF) || !TLI->has(LF))
continue;
+ if (Call->isNoBuiltin())
+ continue;
+ 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;
+ }
switch (LF) {
case LibFunc_sqrtf:
diff --git a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
index e6c2a7e629a5d6..eb9dad33e9de38 100644
--- a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
+++ b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.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=partially-inline-libcalls 2>%t < %s | FileCheck %s
+; RUN: cat %t | FileCheck %s -check-prefix=CHECK-REMARK
define float @f(float %val) {
; CHECK-LABEL: @f(
+; CHECK-REMARK: remark: partially-inline-libcalls: Partially inlined call to sqrt function despite having to use errno for error handling: target has fast sqrt instruction
; 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/strictfp.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
index 8d18d1969b04d3..8c54bea0dd2a67 100644
--- a/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
+++ b/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
@@ -2,6 +2,7 @@
define float @f(float %val) strictfp {
; CHECK-LABEL: @f
+; CHECK-REMARK: remark: partially-inline-libcalls: Partially inlined call to sqrt function despite having to use errno for error handling: target has fast sqrt instruction
; CHECK: call{{.*}}@sqrtf
; CHECK-NOT: call{{.*}}@sqrtf
%res = tail call float @sqrtf(float %val) strictfp
More information about the llvm-commits
mailing list