[llvm] [WIP] Emit missed- and passed-optimization messages when partially inlining sqrt (PR #123966)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 14:07:55 PST 2025
https://github.com/TiborGY updated https://github.com/llvm/llvm-project/pull/123966
>From cd3eda3797a799714f93a6d9cec68bc5523b386b Mon Sep 17 00:00:00 2001
From: GYT <tiborgyri at gmail.com>
Date: Wed, 22 Jan 2025 17:52:25 +0100
Subject: [PATCH] add more msg, test
---
.../Scalar/PartiallyInlineLibCalls.cpp | 43 ++++++++++++++++---
.../X86/good-prototype.ll | 3 +-
2 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index 2b50ccdc2eeb4f..d61bf468461ea0 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;
+ }
+
+ 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..afd4cde36ad09d 100644
--- a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
+++ b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll
@@ -1,8 +1,9 @@
; 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 < %s | FileCheck %s
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
More information about the llvm-commits
mailing list