[llvm] [WIP] Add missed optimization remark if LLVM inserts a branch when optimizing sqrt calls (PR #122644)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 12 10:25:59 PST 2025
https://github.com/TiborGY updated https://github.com/llvm/llvm-project/pull/122644
>From 170bfc9d2e0b4c8b57028091f5283d669ecaf20c Mon Sep 17 00:00:00 2001
From: GYT <tiborgyri at gmail.com>
Date: Sun, 12 Jan 2025 18:14:51 +0100
Subject: [PATCH] Add the prerequisites of emitting opt-remarks from
PartiallyInlineLibCalls
---
.../Scalar/PartiallyInlineLibCalls.cpp | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index 3a699df1cde4df..4992103a6d6569 100644
--- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -22,6 +22,7 @@
#include "llvm/Support/DebugCounter.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include <optional>
using namespace llvm;
@@ -33,7 +34,8 @@ DEBUG_COUNTER(PILCounter, "partially-inline-libcalls-transform",
static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
BasicBlock &CurrBB, Function::iterator &BB,
- const TargetTransformInfo *TTI, DomTreeUpdater *DTU) {
+ const TargetTransformInfo *TTI, DomTreeUpdater *DTU,
+ OptimizationRemarkEmitter *ORE) {
// There is no need to change the IR, since backend will emit sqrt
// instruction if the call has already been marked read-only.
if (Call->onlyReadsMemory())
@@ -103,7 +105,8 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
const TargetTransformInfo *TTI,
- DominatorTree *DT) {
+ DominatorTree *DT,
+ OptimizationRemarkEmitter *ORE) {
std::optional<DomTreeUpdater> DTU;
if (DT)
DTU.emplace(DT, DomTreeUpdater::UpdateStrategy::Lazy);
@@ -140,7 +143,7 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
case LibFunc_sqrt:
if (TTI->haveFastSqrt(Call->getType()) &&
optimizeSQRT(Call, CalledFunc, *CurrBB, BB, TTI,
- DTU ? &*DTU : nullptr))
+ DTU ? &*DTU : nullptr, ORE))
break;
continue;
default:
@@ -160,7 +163,8 @@ PartiallyInlineLibCallsPass::run(Function &F, FunctionAnalysisManager &AM) {
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
auto &TTI = AM.getResult<TargetIRAnalysis>(F);
auto *DT = AM.getCachedResult<DominatorTreeAnalysis>(F);
- if (!runPartiallyInlineLibCalls(F, &TLI, &TTI, DT))
+ auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+ if (!runPartiallyInlineLibCalls(F, &TLI, &TTI, DT, &ORE))
return PreservedAnalyses::all();
PreservedAnalyses PA;
PA.preserve<DominatorTreeAnalysis>();
@@ -181,6 +185,7 @@ class PartiallyInlineLibCallsLegacyPass : public FunctionPass {
AU.addRequired<TargetLibraryInfoWrapperPass>();
AU.addRequired<TargetTransformInfoWrapperPass>();
AU.addPreserved<DominatorTreeWrapperPass>();
+ AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
FunctionPass::getAnalysisUsage(AU);
}
@@ -195,7 +200,8 @@ class PartiallyInlineLibCallsLegacyPass : public FunctionPass {
DominatorTree *DT = nullptr;
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
DT = &DTWP->getDomTree();
- return runPartiallyInlineLibCalls(F, TLI, TTI, DT);
+ auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
+ return runPartiallyInlineLibCalls(F, TLI, TTI, DT, ORE);
}
};
}
More information about the llvm-commits
mailing list