Skip to content

Commit

Permalink
Add convergent attribute during reverse translation of OpControlBarri…
Browse files Browse the repository at this point in the history
…er (#1195)

There is a patch to keep convergent attr during translation of
OpControlBarrier to prevent optimization passes from making barrier calls
control-dependent.
  • Loading branch information
KornevNikita authored Sep 6, 2021
1 parent 403a943 commit 4ccb1b2
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3034,7 +3034,8 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName,
if (isFuncNoUnwind())
Func->addFnAttr(Attribute::NoUnwind);
auto OC = BI->getOpCode();
if (isGroupOpCode(OC) || isIntelSubgroupOpCode(OC))
if (isGroupOpCode(OC) || isIntelSubgroupOpCode(OC) ||
OC == OpControlBarrier)
Func->addFnAttr(Attribute::Convergent);
}
auto Call =
Expand Down
1 change: 0 additions & 1 deletion lib/SPIRV/SPIRVToOCL12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void SPIRVToOCL12Base::visitCallSPIRVMemoryBarrier(CallInst *CI) {

void SPIRVToOCL12Base::visitCallSPIRVControlBarrier(CallInst *CI) {
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent);
mutateCallInstOCL(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Expand Down
1 change: 0 additions & 1 deletion lib/SPIRV/SPIRVToOCL20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ void SPIRVToOCL20Base::visitCallSPIRVMemoryBarrier(CallInst *CI) {

void SPIRVToOCL20Base::visitCallSPIRVControlBarrier(CallInst *CI) {
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent);
mutateCallInstOCL(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Expand Down
2 changes: 1 addition & 1 deletion test/GroupAndSubgroupInstructions.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
; CHECK-SPV-IR: declare spir_func i1 @_Z16__spirv_GroupAllib(i32, i1) #[[#Attrs:]]
; CHECK-SPV-IR: declare spir_func i1 @_Z16__spirv_GroupAnyib(i32, i1) #[[#Attrs]]
; CHECK-SPV-IR: declare spir_func i32 @_Z22__spirv_GroupBroadcastiii(i32, i32, i32) #[[#Attrs]]
; CHECK-SPV-IR: declare spir_func void @_Z22__spirv_ControlBarrieriii(i32, i32, i32) #0
; CHECK-SPV-IR: declare spir_func void @_Z22__spirv_ControlBarrieriii(i32, i32, i32) #[[#Attrs]]
; CHECK-SPV-IR: declare spir_func i32 @_Z17__spirv_GroupIAddiii(i32, i32, i32) #[[#Attrs]]
; CHECK-SPV-IR: declare spir_func float @_Z17__spirv_GroupFAddiif(i32, i32, float) #[[#Attrs]]
; CHECK-SPV-IR: declare spir_func i32 @_Z17__spirv_GroupSMiniii(i32, i32, i32) #[[#Attrs]]
Expand Down
2 changes: 1 addition & 1 deletion test/spirv-ocl-builtins-version.spt
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
; CHECK-LLVM-SPV-IR: call spir_func void @_Z22__spirv_ControlBarrieriii(i32 2, i32 2, i32 2320) [[attr]]
; CHECK-LLVM-SPV-IR: call spir_func void @_Z22__spirv_ControlBarrieriii(i32 2, i32 2, i32 2832) [[attr]]
; FIXME: shall we apply convergent attribute to SPIR-V friendly IR representaiton as well?
; CHECK-LLVM-SPV-IR: attributes [[attr]] = { nounwind }
; CHECK-LLVM-SPV-IR: attributes [[attr]] = { convergent nounwind }

0 comments on commit 4ccb1b2

Please sign in to comment.