Skip to content

Commit b2c14d2

Browse files
matborzyszkowskiigcbot
authored andcommitted
Specify when use private memory for fp64
This change determines when the privMem should be used for cases with fp64.
1 parent bc7ac53 commit b2c14d2

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryUsageAnalysis.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ bool PrivateMemoryUsageAnalysis::runOnModule(Module& M)
4242

4343
bool hasStackCall = false;
4444

45+
m_hasDPDivSqrtEmu = !pCtx->platform.hasNoFP64Inst() && !pCtx->platform.hasCorrectlyRoundedMacros() && pCtx->m_DriverInfo.NeedFP64DivSqrt();
46+
4547
// Run on all functions defined in this module
4648
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
4749
{
@@ -125,7 +127,6 @@ bool PrivateMemoryUsageAnalysis::runOnFunction(Function& F)
125127
CodeGenContext* pCtx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
126128
// This is the condition that double emulation is used.
127129
if ((IGC_IS_FLAG_ENABLED(ForceDPEmulation) ||
128-
(!pCtx->platform.hasNoFP64Inst() && !pCtx->platform.hasCorrectlyRoundedMacros() && pCtx->m_DriverInfo.NeedFP64DivSqrt()) ||
129130
(pCtx->m_DriverInfo.NeedFP64(pCtx->platform.getPlatformInfo().eProductFamily) && pCtx->platform.hasNoFP64Inst())))
130131
{
131132
m_hasPrivateMem = true;
@@ -171,4 +172,26 @@ void PrivateMemoryUsageAnalysis::visitBinaryOperator(llvm::BinaryOperator& I)
171172
break;
172173
}
173174
}
175+
176+
// Check if an instruction is fp64 div to enable privMem
177+
if (m_hasDPDivSqrtEmu)
178+
{
179+
if (I.getOpcode() == Instruction::FDiv)
180+
{
181+
m_hasPrivateMem = true;
182+
}
183+
}
184+
}
185+
186+
void PrivateMemoryUsageAnalysis::visitCallInst(llvm::CallInst& CI)
187+
{
188+
// Check if a sqrtd builtin is called to enable privMem
189+
if (m_hasDPDivSqrtEmu)
190+
{
191+
Function* calledFunc = CI.getCalledFunction();
192+
if (calledFunc->getName().startswith("__builtin_IB_native_sqrtd"))
193+
{
194+
m_hasPrivateMem = true;
195+
}
196+
}
174197
}

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryUsageAnalysis.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ namespace IGC
6161
/// @param I The binary op
6262
void visitBinaryOperator(llvm::BinaryOperator& I);
6363

64+
/// @brief CallInst instructions visitor.
65+
/// Analyzes if there are private memory allocation.
66+
/// @param CI The binary op
67+
void visitCallInst(llvm::CallInst& CI);
68+
6469
private:
6570
/// @brief Function entry point.
6671
/// Finds all alloca instructions in this function, analyzes them and adds
@@ -72,6 +77,9 @@ namespace IGC
7277
/// @brief A flag signaling if the current function uses private memory
7378
bool m_hasPrivateMem;
7479

80+
/// @brief A flag signaling if the platform has partial fp64 emulation
81+
bool m_hasDPDivSqrtEmu = false;
82+
7583
/// @brief MetaData utils used to generate LLVM metadata
7684
IGCMD::MetaDataUtils* m_pMDUtils;
7785
};

0 commit comments

Comments
 (0)