Skip to content

Commit d67ab11

Browse files
authored
[SPIR-V] Move structurizer to ISel prepare (#157886)
Some passes like LoopSimplify/SimplifyCFF are running between IRPasses and ISelPrepare. This is an issue because the structurizer generates OpSelectionMerge/OpLoopMerge instructions at specific places, and those passes are moving them. Moving the structurizer later solves this issue.
1 parent b9fd1e6 commit d67ab11

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ TargetPassConfig *SPIRVTargetMachine::createPassConfig(PassManagerBase &PM) {
189189
void SPIRVPassConfig::addIRPasses() {
190190
TargetPassConfig::addIRPasses();
191191

192+
addPass(createSPIRVRegularizerPass());
193+
addPass(createSPIRVPrepareFunctionsPass(TM));
194+
}
195+
196+
void SPIRVPassConfig::addISelPrepare() {
192197
if (TM.getSubtargetImpl()->isShader()) {
193198
// Vulkan does not allow address space casts. This pass is run to remove
194199
// address space casts that can be removed.
@@ -220,12 +225,7 @@ void SPIRVPassConfig::addIRPasses() {
220225
addPass(createPromoteMemoryToRegisterPass());
221226
}
222227

223-
addPass(createSPIRVRegularizerPass());
224-
addPass(createSPIRVPrepareFunctionsPass(TM));
225228
addPass(createSPIRVStripConvergenceIntrinsicsPass());
226-
}
227-
228-
void SPIRVPassConfig::addISelPrepare() {
229229
addPass(createSPIRVLegalizeImplicitBindingPass());
230230
addPass(createSPIRVEmitIntrinsicsPass(&getTM<SPIRVTargetMachine>()));
231231
if (TM.getSubtargetImpl()->isLogicalSPIRV())
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: %if spirv-tools %{ llc -O3 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
2+
3+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G10"
4+
target triple = "spirv1.6-unknown-vulkan1.3-compute"
5+
6+
define spir_func noundef i32 @_Z7processv() #0 {
7+
entry:
8+
%0 = tail call token @llvm.experimental.convergence.entry()
9+
%2 = tail call i32 @llvm.spv.thread.id.i32(i32 0)
10+
switch i32 %2, label %sw1 [
11+
i32 0, label %sw0
12+
i32 2, label %sw0
13+
]
14+
15+
sw0:
16+
%5 = call spir_func i1 @llvm.spv.wave.any(i1 false) [ "convergencectrl"(token %0) ]
17+
br label %exit
18+
19+
sw1:
20+
%6 = call spir_func i1 @llvm.spv.wave.any(i1 false) [ "convergencectrl"(token %0) ]
21+
br label %exit
22+
23+
exit:
24+
%.sink = phi i1 [ %5, %sw0 ], [ %6, %sw1 ]
25+
%conv.i = zext i1 %.sink to i32
26+
ret i32 %conv.i
27+
}
28+
29+
define internal spir_func void @main() #0 {
30+
entry:
31+
%0 = call token @llvm.experimental.convergence.entry()
32+
%call1 = call spir_func noundef i32 @_Z7processv() #0 [ "convergencectrl"(token %0) ]
33+
ret void
34+
}
35+
36+
declare i1 @llvm.spv.wave.any(i1) #0
37+
declare i32 @llvm.spv.thread.id.i32(i32) #2
38+
declare token @llvm.experimental.convergence.entry() #0
39+
40+
attributes #0 = { convergent mustprogress nocallback nofree nosync nounwind willreturn memory(none) }
41+
attributes #1 = { convergent mustprogress nofree noinline norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) "frame-pointer"="all" "hlsl.numthreads"="4,1,1" "hlsl.shader"="compute" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
42+
attributes #2 = { mustprogress nofree nosync nounwind willreturn memory(none) }

0 commit comments

Comments
 (0)