Skip to content

Commit 2e6433b

Browse files
authored
[clang] Emit convergence tokens for loop in global array init (#140120)
When initializing a global array, a loop is generated, but no convergence is emitted for the loop. This fixes that up.
1 parent fc7857c commit 2e6433b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/CodeGen/CGClass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,8 @@ void CodeGenFunction::EmitCXXAggrConstructorCall(const CXXConstructorDecl *ctor,
20422042
cur->addIncoming(arrayBegin, entryBB);
20432043

20442044
// Inside the loop body, emit the constructor call on the array element.
2045+
if (CGM.shouldEmitConvergenceTokens())
2046+
ConvergenceTokenStack.push_back(emitConvergenceLoopToken(loopBB));
20452047

20462048
// The alignment of the base, adjusted by the size of a single element,
20472049
// provides a conservative estimate of the alignment of every element.
@@ -2101,6 +2103,9 @@ void CodeGenFunction::EmitCXXAggrConstructorCall(const CXXConstructorDecl *ctor,
21012103
// Patch the earlier check to skip over the loop.
21022104
if (zeroCheckBranch) zeroCheckBranch->setSuccessor(0, contBB);
21032105

2106+
if (CGM.shouldEmitConvergenceTokens())
2107+
ConvergenceTokenStack.pop_back();
2108+
21042109
EmitBlock(contBB);
21052110
}
21062111

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -Wno-hlsl-implicit-binding -finclude-default-header -triple spirv-unknown-vulkan-compute -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
2+
3+
// CHECK: define internal spir_func void @__cxx_global_var_init()
4+
// CHECK: [[entry_token:%.*]] = call token @llvm.experimental.convergence.entry()
5+
// CHECK: br label %[[loop_entry:.*]]
6+
7+
// CHECK: [[loop_entry]]:
8+
// CHECK: [[loop_token:%.*]] = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token [[entry_token]]) ]
9+
// CHECK: call void {{.*}} [ "convergencectrl"(token [[loop_token]]) ]
10+
// CHECK: br i1 {{%.*}} label {{%.*}} label %[[loop_entry]]
11+
RWBuffer<float> e[2];
12+
13+
[numthreads(4,1,1)]
14+
void main() {
15+
}
16+

0 commit comments

Comments
 (0)