Skip to content

Commit b413982

Browse files
authored
[SPIR] Set MaxAtomicInlineWidth minimum size to 32 for spir32 and 64 for spir64 (#148997)
Set MaxAtomicInlineWidth the same way as SPIR-V targets in 3cfd0c0. This PR fixes build warning in scoped atomic built-in in #146814: `warning: large atomic operation may incur significant performance penalty; ; the access size (2 bytes) exceeds the max lock-free size (0 bytes) [-Watomic-alignment]`
1 parent 0692572 commit b413982

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang/lib/Basic/Targets/SPIR.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
264264
PointerWidth = PointerAlign = 32;
265265
SizeType = TargetInfo::UnsignedInt;
266266
PtrDiffType = IntPtrType = TargetInfo::SignedInt;
267+
// SPIR32 has support for atomic ops if atomic extension is enabled.
268+
// Take the maximum because it's possible the Host supports wider types.
269+
MaxAtomicInlineWidth = std::max<unsigned char>(MaxAtomicInlineWidth, 32);
267270
resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
268271
"v96:128-v192:256-v256:256-v512:512-v1024:1024-G1");
269272
}
@@ -281,6 +284,9 @@ class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
281284
PointerWidth = PointerAlign = 64;
282285
SizeType = TargetInfo::UnsignedLong;
283286
PtrDiffType = IntPtrType = TargetInfo::SignedLong;
287+
// SPIR64 has support for atomic ops if atomic extension is enabled.
288+
// Take the maximum because it's possible the Host supports wider types.
289+
MaxAtomicInlineWidth = std::max<unsigned char>(MaxAtomicInlineWidth, 64);
284290
resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
285291
"v96:128-v192:256-v256:256-v512:512-v1024:1024-G1");
286292
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown -verify
2+
// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple spir64-unknown-unknown -verify
3+
4+
// expected-no-diagnostics
5+
6+
int fi1a(int *i) {
7+
int v;
8+
__scoped_atomic_load(i, &v, __ATOMIC_RELAXED, __MEMORY_SCOPE_DEVICE);
9+
return v;
10+
}
11+
12+
#ifdef __SPIR64__
13+
long fl1a(long *i) {
14+
long v;
15+
__scoped_atomic_load(i, &v, __ATOMIC_RELAXED, __MEMORY_SCOPE_DEVICE);
16+
return v;
17+
}
18+
#endif

0 commit comments

Comments
 (0)