Skip to content

Commit 87e1da3

Browse files
authored
[HLSL] Mark GroupMemoryBarrierWithGroupSync as convergent (#160175)
`GroupMemoryBarrierWithGroupSync` is required to be marked as convergent so that it can't generate duplicate calls or be moved to identical control flow. Without it, we generate undefined behaviour during optimization. For instance: https://godbolt.org/z/9j3vsq1h3. Testing that the convergent attribute is added is sufficient. There already exists testing, [here](https://github.com/inbelic/llvm-project/blob/main/llvm/test/Transforms/SimplifyCFG/attr-convergent.ll), that it will not be moved as described in the above link.
1 parent e99c43c commit 87e1da3

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@ float4 radians(float4);
28052805
/// call.
28062806

28072807
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_group_memory_barrier_with_group_sync)
2808-
void GroupMemoryBarrierWithGroupSync(void);
2808+
__attribute__((convergent)) void GroupMemoryBarrierWithGroupSync(void);
28092809

28102810
} // namespace hlsl
28112811
#endif //_HLSL_HLSL_ALIAS_INTRINSICS_H_

clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ void test_GroupMemoryBarrierWithGroupSync() {
1717

1818
// CHECK: declare void @llvm.[[TARGET]].group.memory.barrier.with.group.sync() #[[ATTRS:[0-9]+]]
1919
// CHECK-NOT: attributes #[[ATTRS]] = {{.+}}memory(none){{.+}}
20-
// CHECK: attributes #[[ATTRS]] = {
20+
// CHECK: attributes #[[ATTRS]] = {{.+}}convergent{{.+}}

llvm/include/llvm/IR/IntrinsicsDirectX.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,6 @@ def int_dx_firstbituhigh : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0,
160160
def int_dx_firstbitshigh : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_anyint_ty], [IntrNoMem]>;
161161
def int_dx_firstbitlow : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_anyint_ty], [IntrNoMem]>;
162162

163-
def int_dx_group_memory_barrier_with_group_sync : DefaultAttrsIntrinsic<[], [], []>;
163+
def int_dx_group_memory_barrier_with_group_sync
164+
: DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
164165
}

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def int_spv_rsqrt : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty]
127127
: DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrConvergent]>;
128128
def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
129129
def int_spv_radians : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>;
130-
def int_spv_group_memory_barrier_with_group_sync : DefaultAttrsIntrinsic<[], [], []>;
130+
def int_spv_group_memory_barrier_with_group_sync
131+
: DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
131132
def int_spv_discard : DefaultAttrsIntrinsic<[], [], []>;
132133
def int_spv_uclamp : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem]>;
133134
def int_spv_sclamp : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem]>;

0 commit comments

Comments
 (0)