Skip to content

Commit e3b451a

Browse files
KornevNikitavmaksimo
authored andcommitted
Add convergent attribute during reverse translation of OpControlBarrier
There is a patch to keep convergent attr during translation of OpControlBarrier to prevent optimization passes from making barrier calls control-dependent. Original commit: KhronosGroup/SPIRV-LLVM-Translator@4ccb1b2
1 parent 6c20447 commit e3b451a

File tree

5 files changed

+4
-5
lines changed

5 files changed

+4
-5
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3035,7 +3035,8 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName,
30353035
if (isFuncNoUnwind())
30363036
Func->addFnAttr(Attribute::NoUnwind);
30373037
auto OC = BI->getOpCode();
3038-
if (isGroupOpCode(OC) || isIntelSubgroupOpCode(OC))
3038+
if (isGroupOpCode(OC) || isIntelSubgroupOpCode(OC) ||
3039+
OC == OpControlBarrier)
30393040
Func->addFnAttr(Attribute::Convergent);
30403041
}
30413042
auto Call =

llvm-spirv/lib/SPIRV/SPIRVToOCL12.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ void SPIRVToOCL12Base::visitCallSPIRVMemoryBarrier(CallInst *CI) {
8989

9090
void SPIRVToOCL12Base::visitCallSPIRVControlBarrier(CallInst *CI) {
9191
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
92-
Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent);
9392
mutateCallInstOCL(
9493
M, CI,
9594
[=](CallInst *, std::vector<Value *> &Args) {

llvm-spirv/lib/SPIRV/SPIRVToOCL20.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ void SPIRVToOCL20Base::visitCallSPIRVMemoryBarrier(CallInst *CI) {
9797

9898
void SPIRVToOCL20Base::visitCallSPIRVControlBarrier(CallInst *CI) {
9999
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
100-
Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent);
101100
mutateCallInstOCL(
102101
M, CI,
103102
[=](CallInst *, std::vector<Value *> &Args) {

llvm-spirv/test/GroupAndSubgroupInstructions.spvasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
; CHECK-SPV-IR: declare spir_func i1 @_Z16__spirv_GroupAllib(i32, i1) #[[#Attrs:]]
7979
; CHECK-SPV-IR: declare spir_func i1 @_Z16__spirv_GroupAnyib(i32, i1) #[[#Attrs]]
8080
; CHECK-SPV-IR: declare spir_func i32 @_Z22__spirv_GroupBroadcastiii(i32, i32, i32) #[[#Attrs]]
81-
; CHECK-SPV-IR: declare spir_func void @_Z22__spirv_ControlBarrieriii(i32, i32, i32) #0
81+
; CHECK-SPV-IR: declare spir_func void @_Z22__spirv_ControlBarrieriii(i32, i32, i32) #[[#Attrs]]
8282
; CHECK-SPV-IR: declare spir_func i32 @_Z17__spirv_GroupIAddiii(i32, i32, i32) #[[#Attrs]]
8383
; CHECK-SPV-IR: declare spir_func float @_Z17__spirv_GroupFAddiif(i32, i32, float) #[[#Attrs]]
8484
; CHECK-SPV-IR: declare spir_func i32 @_Z17__spirv_GroupSMiniii(i32, i32, i32) #[[#Attrs]]

llvm-spirv/test/spirv-ocl-builtins-version.spt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@
6565
; CHECK-LLVM-SPV-IR: call spir_func void @_Z22__spirv_ControlBarrieriii(i32 2, i32 2, i32 2320) [[attr]]
6666
; CHECK-LLVM-SPV-IR: call spir_func void @_Z22__spirv_ControlBarrieriii(i32 2, i32 2, i32 2832) [[attr]]
6767
; FIXME: shall we apply convergent attribute to SPIR-V friendly IR representaiton as well?
68-
; CHECK-LLVM-SPV-IR: attributes [[attr]] = { nounwind }
68+
; CHECK-LLVM-SPV-IR: attributes [[attr]] = { convergent nounwind }

0 commit comments

Comments
 (0)