Skip to content

Commit d03728a

Browse files
Gang Y Chenigcbot
authored andcommitted
fix ResourceLoop Bug2
Need to consider the interaction with payload coalescing
1 parent dc33900 commit d03728a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

IGC/Compiler/CISACodeGen/CoalescingEngine.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ IGC_INITIALIZE_PASS_DEPENDENCY(CodeGenPatternMatch)
5050
IGC_INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
5151
IGC_INITIALIZE_PASS_DEPENDENCY(DeSSA)
5252
IGC_INITIALIZE_PASS_DEPENDENCY(MetaDataUtilsWrapper)
53+
IGC_INITIALIZE_PASS_DEPENDENCY(ResourceLoopAnalysis)
5354
IGC_INITIALIZE_PASS_END(CoalescingEngine, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS)
5455

5556
namespace IGC
@@ -70,6 +71,7 @@ namespace IGC
7071
AU.addRequired<DeSSA>();
7172
AU.addRequired<MetaDataUtilsWrapper>();
7273
AU.addRequired<CodeGenContextWrapper>();
74+
AU.addRequired<ResourceLoopAnalysis>();
7375
}
7476

7577
void CoalescingEngine::CCTuple::print(raw_ostream& OS, const Module*) const
@@ -127,6 +129,7 @@ namespace IGC
127129
WIA = &getAnalysis<WIAnalysis>();
128130
CG = &getAnalysis<CodeGenPatternMatch>();
129131
LV = &getAnalysis<LiveVarsAnalysis>().getLiveVars();
132+
RLA = &getAnalysis<ResourceLoopAnalysis>();
130133
if (IGC_IS_FLAG_ENABLED(EnableDeSSA)) {
131134
m_DeSSA = &getAnalysis<DeSSA>();
132135
}
@@ -239,7 +242,19 @@ namespace IGC
239242
}
240243

241244
}
242-
245+
#if 0
246+
// turn off coalescing when inst is inside a fused resource-loop
247+
// feels like this approach may not be strong enough.
248+
// So opt to the solution of disabling coalescing in whole BB
249+
auto loopMarker =
250+
RLA->GetResourceLoopMarker(tupleGeneratingInstruction);
251+
if ((loopMarker & ResourceLoopAnalysis::MarkResourceLoopInside) ||
252+
((loopMarker & ResourceLoopAnalysis::MarkResourceLoopStart) &&
253+
!(loopMarker & ResourceLoopAnalysis::MarkResourceLoopEnd)))
254+
{
255+
return;
256+
}
257+
#endif
243258
IGC_ASSERT(numOperands >= 2);
244259

245260
//No result, but has side effects of updating the split mapping.
@@ -1422,6 +1437,17 @@ namespace IGC
14221437
//Loop through instructions top to bottom
14231438
for (I = instructionList.begin(), E = instructionList.end(); I != E; ++I) {
14241439
llvm::Instruction& inst = (*I);
1440+
auto loopMarker =
1441+
RLA->GetResourceLoopMarker(&inst);
1442+
// turn off coalescing in this block when there is a fused resource-loop
1443+
if ((loopMarker & ResourceLoopAnalysis::MarkResourceLoopInside) ||
1444+
((loopMarker & ResourceLoopAnalysis::MarkResourceLoopStart) &&
1445+
!(loopMarker & ResourceLoopAnalysis::MarkResourceLoopEnd)))
1446+
{
1447+
BBProcessingDefs[bb].clear();
1448+
return;
1449+
}
1450+
14251451
visit(inst);
14261452
}
14271453
}

IGC/Compiler/CISACodeGen/CoalescingEngine.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SPDX-License-Identifier: MIT
99
#pragma once
1010

1111
#include "Compiler/CISACodeGen/WIAnalysis.hpp"
12+
#include "Compiler/CISACodeGen/ResourceLoopAnalysis.h"
1213
#include "Compiler/CISACodeGen/PatternMatchPass.hpp"
1314
#include "Compiler/MetaDataUtilsWrapper.h"
1415
#include "Compiler/CISACodeGen/PayloadMapping.hpp"
@@ -958,6 +959,7 @@ namespace IGC {
958959
LiveVars* LV;
959960
WIAnalysis* WIA;
960961
DeSSA* m_DeSSA;
962+
ResourceLoopAnalysis* RLA;
961963
CodeGenPatternMatch* CG;
962964
llvm::DenseMap<llvm::Value*, ElementNode*> ValueNodeMap;
963965
llvm::DenseMap<ElementNode*, CCTuple*> NodeCCTupleMap;

0 commit comments

Comments
 (0)