Skip to content

Commit 558277a

Browse files
[clang][ARM] Fix setting of MaxAtomicInlineWidth. (#151404)
2f497ec updated the backend's rules for when lock-free atomics are available, but we never made a corresponding change to the frontend. Fix it to be consistent. This only affects targets older than v7.
1 parent bda9272 commit 558277a

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,24 @@ void ARMTargetInfo::setArchInfo(llvm::ARM::ArchKind Kind) {
133133
}
134134

135135
void ARMTargetInfo::setAtomic() {
136-
// when triple does not specify a sub arch,
137-
// then we are not using inline atomics
138-
bool ShouldUseInlineAtomic =
139-
(ArchISA == llvm::ARM::ISAKind::ARM && ArchVersion >= 6) ||
140-
(ArchISA == llvm::ARM::ISAKind::THUMB && ArchVersion >= 7);
141-
// Cortex M does not support 8 byte atomics, while general Thumb2 does.
142136
if (ArchProfile == llvm::ARM::ProfileKind::M) {
137+
// M-class only ever supports 32-bit atomics. Cortex-M0 doesn't have
138+
// any atomics.
143139
MaxAtomicPromoteWidth = 32;
144-
if (ShouldUseInlineAtomic)
140+
if (ArchVersion >= 7)
145141
MaxAtomicInlineWidth = 32;
146142
} else {
143+
// A-class targets have up to 64-bit atomics.
144+
//
145+
// On Linux, 64-bit atomics are always available through kernel helpers
146+
// (which are lock-free). Otherwise, atomics are available on v6 or later.
147+
//
148+
// (Thumb doesn't matter; for Thumbv6, we just use a library call which
149+
// switches out of Thumb mode.)
150+
//
151+
// This should match setMaxAtomicSizeInBitsSupported() in the backend.
147152
MaxAtomicPromoteWidth = 64;
148-
if (ShouldUseInlineAtomic)
153+
if (getTriple().getOS() == llvm::Triple::Linux || ArchVersion >= 6)
149154
MaxAtomicInlineWidth = 64;
150155
}
151156
}

clang/test/CodeGen/atomic-arm.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// RUN: %clang_cc1 -triple thumbv7m-apple-unknown-macho %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-V7M
33
// RUN: %clang_cc1 -triple thumbv7-apple-ios13.0 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-HOSTED
44
// RUN: %clang_cc1 -triple thumbv7k-apple-watchos5.0 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-HOSTED
5-
5+
// RUN: %clang_cc1 -triple arm-linux-gnueabi %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-HOSTED
6+
// RUN: %clang_cc1 -triple armv7-none-eabi %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-HOSTED
7+
// RUN: %clang_cc1 -triple thumbv6k-none-eabi %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-HOSTED
8+
// RUN: %clang_cc1 -triple armv5-none-eabi %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-V6M
69

710
// CHECK-V6M: @always1 = global i32 0
811
// CHECK-V6M: @always4 = global i32 0
@@ -22,7 +25,7 @@ int always8 = __atomic_always_lock_free(8, 0);
2225

2326
int lock_free_1() {
2427
// CHECK-LABEL: @lock_free_1
25-
// CHECK-V6M: [[RES:%.*]] = call arm_aapcscc zeroext i1 @__atomic_is_lock_free(i32 noundef 1, ptr noundef null)
28+
// CHECK-V6M: [[RES:%.*]] = call{{.*}}zeroext i1 @__atomic_is_lock_free(i32 noundef 1, ptr noundef null)
2629
// CHECK-V6M: [[RES32:%.*]] = zext i1 [[RES]] to i32
2730
// CHECK-V6M: ret i32 [[RES32]]
2831

@@ -33,7 +36,7 @@ int lock_free_1() {
3336

3437
int lock_free_4() {
3538
// CHECK-LABEL: @lock_free_4
36-
// CHECK-V6M: [[RES:%.*]] = call arm_aapcscc zeroext i1 @__atomic_is_lock_free(i32 noundef 4, ptr noundef null)
39+
// CHECK-V6M: [[RES:%.*]] = call{{.*}}zeroext i1 @__atomic_is_lock_free(i32 noundef 4, ptr noundef null)
3740
// CHECK-V6M: [[RES32:%.*]] = zext i1 [[RES]] to i32
3841
// CHECK-V6M: ret i32 [[RES32]]
3942

@@ -44,11 +47,11 @@ int lock_free_4() {
4447

4548
int lock_free_8() {
4649
// CHECK-LABEL: @lock_free_8
47-
// CHECK-V6M: [[RES:%.*]] = call arm_aapcscc zeroext i1 @__atomic_is_lock_free(i32 noundef 8, ptr noundef null)
50+
// CHECK-V6M: [[RES:%.*]] = call{{.*}}zeroext i1 @__atomic_is_lock_free(i32 noundef 8, ptr noundef null)
4851
// CHECK-V6M: [[RES32:%.*]] = zext i1 [[RES]] to i32
4952
// CHECK-V6M: ret i32 [[RES32]]
5053

51-
// CHECK-V7M: [[RES:%.*]] = call arm_aapcscc zeroext i1 @__atomic_is_lock_free(i32 noundef 8, ptr noundef null)
54+
// CHECK-V7M: [[RES:%.*]] = call{{.*}}zeroext i1 @__atomic_is_lock_free(i32 noundef 8, ptr noundef null)
5255
// CHECK-V7M: [[RES32:%.*]] = zext i1 [[RES]] to i32
5356
// CHECK-V7M: ret i32 [[RES32]]
5457

clang/test/CodeGen/pr45476.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple arm-unknown-linux-gnueabi -emit-llvm %s -o - | FileCheck -check-prefix=LIBCALL %s
1+
// RUN: %clang_cc1 -triple armv6m-eabi -emit-llvm %s -o - | FileCheck -check-prefix=LIBCALL %s
22
// RUN: %clang_cc1 -triple armv8-eabi -emit-llvm %s -o - | FileCheck -check-prefix=NATIVE %s
33
// PR45476
44

0 commit comments

Comments
 (0)