Skip to content

Commit 7c71ec5

Browse files
Artem Gindinsonfda0
authored andcommitted
Trivially eliminate TrivialLocalMemoryOpsElimination pass
Follow up on commit 3ae1be7 by dropping the unused pass - no observable performance impact has been confirmed. (cherry picked from commit 6a215e5)
1 parent d460fe1 commit 7c71ec5

File tree

8 files changed

+0
-527
lines changed

8 files changed

+0
-527
lines changed

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,179 +2450,6 @@ void CustomSafeOptPass::visitExtractElementInst(ExtractElementInst& I)
24502450
dp4WithIdentityMatrix(I);
24512451
}
24522452

2453-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2454-
// This pass removes dead local memory loads and stores. If we remove all such loads and stores, we also
2455-
// remove all local memory fences together with barriers that follow.
2456-
//
2457-
IGC_INITIALIZE_PASS_BEGIN(TrivialLocalMemoryOpsElimination, "TrivialLocalMemoryOpsElimination", "TrivialLocalMemoryOpsElimination", false, false)
2458-
IGC_INITIALIZE_PASS_END(TrivialLocalMemoryOpsElimination, "TrivialLocalMemoryOpsElimination", "TrivialLocalMemoryOpsElimination", false, false)
2459-
2460-
char TrivialLocalMemoryOpsElimination::ID = 0;
2461-
2462-
TrivialLocalMemoryOpsElimination::TrivialLocalMemoryOpsElimination() : FunctionPass(ID)
2463-
{
2464-
initializeTrivialLocalMemoryOpsEliminationPass(*PassRegistry::getPassRegistry());
2465-
}
2466-
2467-
bool TrivialLocalMemoryOpsElimination::runOnFunction(Function& F)
2468-
{
2469-
bool change = false;
2470-
2471-
IGCMD::MetaDataUtils* pMdUtil = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
2472-
if (!isEntryFunc(pMdUtil, &F))
2473-
{
2474-
// Skip if it is non-entry function. For example, a subroutine
2475-
// foo ( local int* p) { ...... store v, p; ......}
2476-
// in which no localMemoptimization will be performed.
2477-
return change;
2478-
}
2479-
2480-
visit(F);
2481-
if (!abortPass && (m_LocalLoadsToRemove.empty() ^ m_LocalStoresToRemove.empty()))
2482-
{
2483-
for (StoreInst* Inst : m_LocalStoresToRemove)
2484-
{
2485-
Inst->eraseFromParent();
2486-
change = true;
2487-
}
2488-
2489-
for (LoadInst* Inst : m_LocalLoadsToRemove)
2490-
{
2491-
if (Inst->use_empty())
2492-
{
2493-
Inst->eraseFromParent();
2494-
change = true;
2495-
}
2496-
}
2497-
2498-
for (CallInst* Inst : m_LocalFencesBariersToRemove)
2499-
{
2500-
Inst->eraseFromParent();
2501-
change = true;
2502-
}
2503-
}
2504-
m_LocalStoresToRemove.clear();
2505-
m_LocalLoadsToRemove.clear();
2506-
m_LocalFencesBariersToRemove.clear();
2507-
2508-
return change;
2509-
}
2510-
2511-
/*
2512-
OCL instruction barrier(CLK_LOCAL_MEM_FENCE); is translate to two instructions
2513-
call void @llvm.genx.GenISA.memoryfence(i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true)
2514-
call void @llvm.genx.GenISA.threadgroupbarrier()
2515-
2516-
if we remove call void @llvm.genx.GenISA.memoryfence(i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true)
2517-
we must remove next instruction if it is call void @llvm.genx.GenISA.threadgroupbarrier()
2518-
*/
2519-
void TrivialLocalMemoryOpsElimination::findNextThreadGroupBarrierInst(Instruction& I)
2520-
{
2521-
auto nextInst = I.getNextNonDebugInstruction();
2522-
if (isa<GenIntrinsicInst>(nextInst))
2523-
{
2524-
GenIntrinsicInst* II = cast<GenIntrinsicInst>(nextInst);
2525-
if (II->getIntrinsicID() == GenISAIntrinsic::GenISA_threadgroupbarrier)
2526-
{
2527-
m_LocalFencesBariersToRemove.push_back(dyn_cast<CallInst>(nextInst));
2528-
}
2529-
}
2530-
}
2531-
2532-
void TrivialLocalMemoryOpsElimination::visitLoadInst(LoadInst& I)
2533-
{
2534-
if (I.getPointerAddressSpace() == ADDRESS_SPACE_LOCAL)
2535-
{
2536-
m_LocalLoadsToRemove.push_back(&I);
2537-
}
2538-
else if (I.getPointerAddressSpace() == ADDRESS_SPACE_GENERIC)
2539-
{
2540-
abortPass = true;
2541-
}
2542-
}
2543-
2544-
void TrivialLocalMemoryOpsElimination::visitStoreInst(StoreInst& I)
2545-
{
2546-
if (I.getPointerAddressSpace() == ADDRESS_SPACE_LOCAL)
2547-
{
2548-
if (auto *GV = dyn_cast<GlobalVariable>(I.getPointerOperand()->stripPointerCasts()))
2549-
{
2550-
// Device sanitizer instrumentation pass inserts a new local memory
2551-
// variable and inserts store to the variable in a kernel. The
2552-
// variable is loaded later in no-inline functions. For this case,
2553-
// do not eliminate the store.
2554-
if (GV->getName().startswith("__Asan"))
2555-
{
2556-
return;
2557-
}
2558-
}
2559-
m_LocalStoresToRemove.push_back(&I);
2560-
}
2561-
else if (I.getPointerAddressSpace() == ADDRESS_SPACE_GENERIC)
2562-
{
2563-
abortPass = true;
2564-
}
2565-
}
2566-
2567-
bool TrivialLocalMemoryOpsElimination::isLocalBarrier(CallInst& I)
2568-
{
2569-
//check arguments in call void @llvm.genx.GenISA.memoryfence(i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true) if match to
2570-
// (i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true) it is local barrier
2571-
std::vector<bool> argumentsOfMemoryBarrier;
2572-
2573-
for (auto arg = I.arg_begin(); arg != I.arg_end(); ++arg)
2574-
{
2575-
ConstantInt* ci = dyn_cast<ConstantInt>(arg);
2576-
if (ci) {
2577-
argumentsOfMemoryBarrier.push_back(ci->getValue().getBoolValue());
2578-
}
2579-
else {
2580-
// argument is not a constant, so we can't tell.
2581-
return false;
2582-
}
2583-
}
2584-
2585-
return argumentsOfMemoryBarrier == m_argumentsOfLocalMemoryBarrier;
2586-
}
2587-
2588-
// If any call instruction use pointer to local memory abort pass execution
2589-
void TrivialLocalMemoryOpsElimination::anyCallInstUseLocalMemory(CallInst& I)
2590-
{
2591-
Function* fn = I.getCalledFunction();
2592-
2593-
if (fn != NULL)
2594-
{
2595-
for (auto arg = fn->arg_begin(); arg != fn->arg_end(); ++arg)
2596-
{
2597-
if (arg->getType()->isPointerTy())
2598-
{
2599-
if (arg->getType()->getPointerAddressSpace() == ADDRESS_SPACE_LOCAL || arg->getType()->getPointerAddressSpace() == ADDRESS_SPACE_GENERIC) abortPass = true;
2600-
}
2601-
}
2602-
}
2603-
}
2604-
2605-
void TrivialLocalMemoryOpsElimination::visitCallInst(CallInst& I)
2606-
{
2607-
// detect only: llvm.genx.GenISA.memoryfence(i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 true)
2608-
// (note: the first and last arguments are true)
2609-
// and add them with immediately following barriers to m_LocalFencesBariersToRemove
2610-
anyCallInstUseLocalMemory(I);
2611-
2612-
if (isa<GenIntrinsicInst>(I))
2613-
{
2614-
GenIntrinsicInst* II = cast<GenIntrinsicInst>(&I);
2615-
if (II->getIntrinsicID() == GenISAIntrinsic::GenISA_memoryfence)
2616-
{
2617-
if (isLocalBarrier(I))
2618-
{
2619-
m_LocalFencesBariersToRemove.push_back(&I);
2620-
findNextThreadGroupBarrierInst(I);
2621-
}
2622-
}
2623-
}
2624-
}
2625-
26262453
////////////////////////////////////////////////////////////////////////////////
26272454
IGC_INITIALIZE_PASS_BEGIN(TrivialUnnecessaryTGMFenceElimination, "TrivialUnnecessaryTGMFenceElimination", "TrivialUnnecessaryTGMFenceElimination", false, false)
26282455
IGC_INITIALIZE_PASS_END(TrivialUnnecessaryTGMFenceElimination, "TrivialUnnecessaryTGMFenceElimination", "TrivialUnnecessaryTGMFenceElimination", false, false)

IGC/Compiler/CustomSafeOptPass.hpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -108,43 +108,6 @@ namespace IGC
108108
llvm::Value* analyzeTreeForTrunc64bto32b(const llvm::Use& OperandUse, llvm::SmallVector<llvm::BinaryOperator*, 8>& OpsToDelete);
109109
};
110110

111-
// TODO: Remove this pass as unused
112-
class TrivialLocalMemoryOpsElimination : public llvm::FunctionPass, public llvm::InstVisitor<TrivialLocalMemoryOpsElimination>
113-
{
114-
public:
115-
static char ID;
116-
117-
TrivialLocalMemoryOpsElimination();
118-
119-
virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override
120-
{
121-
AU.addRequired<CodeGenContextWrapper>();
122-
AU.addRequired<MetaDataUtilsWrapper>();
123-
AU.setPreservesCFG();
124-
}
125-
126-
virtual bool runOnFunction(llvm::Function& F) override;
127-
128-
virtual llvm::StringRef getPassName() const override
129-
{
130-
return "TrivialLocalMemoryOpsElimination";
131-
}
132-
133-
void visitLoadInst(llvm::LoadInst& I);
134-
void visitStoreInst(llvm::StoreInst& I);
135-
void visitCallInst(llvm::CallInst& I);
136-
bool isLocalBarrier(llvm::CallInst& I);
137-
void findNextThreadGroupBarrierInst(llvm::Instruction& I);
138-
void anyCallInstUseLocalMemory(llvm::CallInst& I);
139-
140-
private:
141-
llvm::SmallVector<llvm::LoadInst*, 16> m_LocalLoadsToRemove;
142-
llvm::SmallVector<llvm::StoreInst*, 16> m_LocalStoresToRemove;
143-
llvm::SmallVector<llvm::CallInst*, 16> m_LocalFencesBariersToRemove;
144-
145-
bool abortPass = false;
146-
const std::vector<bool> m_argumentsOfLocalMemoryBarrier{ true, false, false, false, false, false, true };
147-
};
148111
class TrivialUnnecessaryTGMFenceElimination : public llvm::FunctionPass, public llvm::InstVisitor<TrivialUnnecessaryTGMFenceElimination>
149112
{
150113
public:

IGC/Compiler/InitializePasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ void initializeRegisterEstimatorPass(llvm::PassRegistry&);
232232
void initializeVariableReuseAnalysisPass(llvm::PassRegistry &);
233233
void initializeResourceLoopAnalysisPass(llvm::PassRegistry &);
234234
void initializeTranslationTablePass(llvm::PassRegistry&);
235-
void initializeTrivialLocalMemoryOpsEliminationPass(llvm::PassRegistry&);
236235
void initializeTrivialUnnecessaryTGMFenceEliminationPass(llvm::PassRegistry&);
237236
void initializeSLMConstPropPass(llvm::PassRegistry&);
238237
void initializeBlendToDiscardPass(llvm::PassRegistry&);

IGC/Compiler/tests/DebugInfo/TrivialLocalMemoryOpsElimination-typed-pointers.ll

Lines changed: 0 additions & 72 deletions
This file was deleted.

IGC/Compiler/tests/DebugInfo/TrivialLocalMemoryOpsElimination.ll

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)