Skip to content

Commit 157431a

Browse files
igcbotmmerecki
andauthored
Fix condition for running the AddRequiredMemoryFences pass (#21289)
This PR updates the condition for running the `AddRequiredMemoryFences` pass. The pass must also be run if shader has SLM atomic instructions. Co-authored-by: Merecki, Mariusz <[email protected]>
1 parent be74db2 commit 157431a

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void CheckInstrTypes::print(llvm::raw_ostream& OS) const
159159
OS << "\nhasGenericAddressSpacePointers: " << g_InstrTypes.hasGenericAddressSpacePointers;
160160
OS << "\nhasDebugInfo: " << g_InstrTypes.hasDebugInfo;
161161
OS << "\nhasAtomics: " << g_InstrTypes.hasAtomics;
162+
OS << "\nhasLocalAtomics: " << g_InstrTypes.hasLocalAtomics;
162163
OS << "\nhasDiscard: " << g_InstrTypes.hasDiscard;
163164
OS << "\nhasTypedRead: " << g_InstrTypes.hasTypedRead;
164165
OS << "\nhasTypedwrite: " << g_InstrTypes.hasTypedwrite;
@@ -311,9 +312,18 @@ void CheckInstrTypes::visitCallInst(CallInst& C)
311312
case GenISAIntrinsic::GenISA_LSCAtomicFP64:
312313
case GenISAIntrinsic::GenISA_LSCAtomicFP32:
313314
case GenISAIntrinsic::GenISA_LSCAtomicInts:
315+
{
314316
g_InstrTypes.hasAtomics = true;
315317
g_InstrTypes.numAtomics++;
318+
Value* bufPtr = GetBufferOperand(CI);
319+
if (bufPtr &&
320+
bufPtr->getType()->isPointerTy() &&
321+
ADDRESS_SPACE_LOCAL == bufPtr->getType()->getPointerAddressSpace())
322+
{
323+
g_InstrTypes.hasLocalAtomics = true;
324+
}
316325
break;
326+
}
317327
case GenISAIntrinsic::GenISA_discard:
318328
g_InstrTypes.hasDiscard = true;
319329
break;

IGC/Compiler/CISACodeGen/ShaderCodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ void AddLegalizationPasses(CodeGenContext& ctx, IGCPassManager& mpm, PSSignature
11171117
mpm.add(new RuntimeValueLegalizationPass());
11181118
}
11191119

1120-
if (ctx.m_instrTypes.hasLocalLoadStore &&
1120+
if ((ctx.m_instrTypes.hasLocalLoadStore || ctx.m_instrTypes.hasLocalAtomics) &&
11211121
ctx.platform.hasLSC() &&
11221122
!ctx.platform.NeedsLSCFenceUGMBeforeEOT() && // VISA will add the fence
11231123
IGC_IS_FLAG_DISABLED(DisableAddRequiredMemoryFencesPass))

IGC/Compiler/CodeGenPublic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ namespace IGC
332332
bool hasGenericAddressSpacePointers{};
333333
bool hasDebugInfo{}; //<! true only if module contains debug info !llvm.dbg.cu
334334
bool hasAtomics{};
335+
bool hasLocalAtomics{};
335336
bool hasDiscard{};
336337
bool hasTypedRead{};
337338
bool hasTypedwrite{};
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
; REQUIRES: llvm-14-plus, regkeys
9+
; RUN: igc_opt --opaque-pointers --regkey PrintToConsole --CheckInstrTypes -igc-serialize-metadata --enable-instrtypes-print -S < %s 2>&1 | FileCheck %s
10+
; ------------------------------------------------
11+
; CheckInstrTypes
12+
; ------------------------------------------------
13+
14+
; Test checks metrics gathered by CheckInstrTypes pass
15+
16+
define void @test(ptr addrspace(3) %addr) {
17+
entry:
18+
%dummy = call i32 @llvm.genx.GenISA.intatomicrawA64.i32.p3i32.p3i32(ptr addrspace(3) %addr, ptr addrspace(3) %addr, i32 0, i32 9)
19+
ret void
20+
}
21+
22+
; Test checks metrics gathered by CheckInstrTypes pass
23+
24+
; CHECK: CorrelatedValuePropagationEnable: 0
25+
; CHECK: hasMultipleBB: 0
26+
; CHECK: hasCmp: 0
27+
; CHECK: hasSwitch: 0
28+
; CHECK: hasPhi: 0
29+
; CHECK: hasLoadStore: 0
30+
; CHECK: hasIndirectCall: 0
31+
; CHECK: hasInlineAsm: 0
32+
; CHECK: hasInlineAsmPointerAccess: 0
33+
; CHECK: hasIndirectBranch: 0
34+
; CHECK: hasFunctionAddressTaken: 0
35+
; CHECK: hasSel: 0
36+
; CHECK: hasPointer: 0
37+
; CHECK: hasLocalLoadStore: 0
38+
; CHECK: hasGlobalLoad: 0
39+
; CHECK: hasGlobalStore: 0
40+
; CHECK: hasStorageBufferLoad: 0
41+
; CHECK: hasStorageBufferStore: 0
42+
; CHECK: hasSubroutines: 0
43+
; CHECK: hasPrimitiveAlloca: 0
44+
; CHECK: hasNonPrimitiveAlloca: 0
45+
; CHECK: hasReadOnlyArray: 0
46+
; CHECK: hasBuiltin: 0
47+
; CHECK: hasFRem: 0
48+
; CHECK: psHasSideEffect: 1
49+
; CHECK: hasGenericAddressSpacePointers: 0
50+
; CHECK: hasDebugInfo: 0
51+
; CHECK: hasAtomics: 1
52+
; CHECK: hasLocalAtomics: 1
53+
; CHECK: hasDiscard: 0
54+
; CHECK: hasTypedRead: 0
55+
; CHECK: hasTypedwrite: 0
56+
; CHECK: mayHaveIndirectOperands: 0
57+
; CHECK: mayHaveIndirectResources: 0
58+
; CHECK: hasUniformAssumptions: 0
59+
; CHECK: sampleCmpToDiscardOptimizationPossible: 0
60+
; CHECK: hasRuntimeValueVector: 0
61+
; CHECK: hasDynamicGenericLoadStore: 0
62+
; CHECK: hasUnmaskedRegion: 0
63+
; CHECK: hasSLM: 0
64+
; CHECK: numCall: 1
65+
; CHECK: numBarrier: 0
66+
; CHECK: numLoadStore: 0
67+
; CHECK: numWaveIntrinsics: 0
68+
; CHECK: numAtomics: 1
69+
; CHECK: numTypedReadWrite: 0
70+
; CHECK: numAllInsts: 2
71+
; CHECK: sampleCmpToDiscardOptimizationSlot: 0
72+
; CHECK: numSample: 0
73+
; CHECK: numBB: 1
74+
; CHECK: numLoopInsts: 0
75+
; CHECK: numOfLoop: 0
76+
; CHECK: numInsts: 2
77+
; CHECK: numAllocaInsts: 0
78+
; CHECK: numPsInputs: 0
79+
; CHECK: hasPullBary: 0
80+
; CHECK: numGlobalInsts: 0
81+
; CHECK: numLocalInsts: 2
82+
; CHECK: numSamplesVaryingResource: 0
83+
; CHECK: numUntyped: 0
84+
; CHECK: num1DAccesses: 0
85+
; CHECK: num2DAccesses: 0
86+
; CHECK: numSLMAccesses: 0
87+
88+
; Function Attrs: argmemonly nounwind
89+
declare i32 @llvm.genx.GenISA.intatomicrawA64.i32.p3i32.p3i32(ptr addrspace(3), ptr addrspace(3), i32, i32) #2
90+
91+
attributes #0 = { null_pointer_is_valid }
92+
attributes #1 = { nounwind readnone }
93+
attributes #2 = { argmemonly nounwind }
94+
95+
!IGCMetadata = !{!1}
96+
97+
!1 = !{!"ModuleMD"}

0 commit comments

Comments
 (0)