Skip to content

Commit 88273a0

Browse files
authored
[AArch64] Disable cortex-a53-835769 when compiling for armv8.1-a or later (#170649)
Any code compiled with armv8.1-a or later cannot run on a cortex-a53, so does not need to enable the 835769 errata fix. This patch disables the +fix-cortex-a53-835769 feature when the architecture is later than armv8.0-a. The command line flag -mfix_cortex_a53_835769 will still enable it.
1 parent 4ef5cef commit 88273a0

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

clang/lib/Driver/ToolChains/Arch/AArch64.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,18 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
453453
Features.push_back("+fix-cortex-a53-835769");
454454
else
455455
Features.push_back("-fix-cortex-a53-835769");
456-
} else if (Triple.isAndroid() || Triple.isOHOSFamily()) {
457-
// Enabled A53 errata (835769) workaround by default on android
458-
Features.push_back("+fix-cortex-a53-835769");
459-
} else if (Triple.isOSFuchsia()) {
460-
std::string CPU = getCPUName(D, Args, Triple);
461-
if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53")
456+
} else if (Extensions.BaseArch &&
457+
Extensions.BaseArch->Version.getMajor() == 8 &&
458+
Extensions.BaseArch->Version.getMinor() == 0) {
459+
if (Triple.isAndroid() || Triple.isOHOSFamily()) {
460+
// Enabled A53 errata (835769) workaround by default on android, providing
461+
// that the architecture allows running on a cortex-a53.
462462
Features.push_back("+fix-cortex-a53-835769");
463+
} else if (Triple.isOSFuchsia()) {
464+
std::string CPU = getCPUName(D, Args, Triple);
465+
if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53")
466+
Features.push_back("+fix-cortex-a53-835769");
467+
}
463468
}
464469

465470
if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))

clang/test/CodeGen/AArch64/fix-cortex-a53-835769.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
// RUN: | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s
1010
// RUN: %clang -O3 -target aarch64-linux-ohos %s -S -o- \
1111
// RUN: | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s
12+
// RUN: %clang -O3 --target=aarch64-linux-androideabi -march=armv8.1-a %s -S -o- \
13+
// RUN: | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
14+
// RUN: %clang -O3 -target aarch64-linux-ohos -march=armv8.1-a %s -S -o- \
15+
// RUN: | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
16+
// RUN: %clang -O3 --target=aarch64-linux-androideabi -mcpu=cortex-a55 %s -S -o- \
17+
// RUN: | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
18+
// RUN: %clang -O3 -target aarch64-linux-ohos -mcpu=cortex-a55 %s -S -o- \
19+
// RUN: | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
1220
// RUN: %clang -O3 --target=aarch64-linux-androideabi -mfix-cortex-a53-835769 %s -S -o- \
1321
// RUN: | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s
1422
// RUN: %clang -O3 --target=aarch64-linux-androideabi -mno-fix-cortex-a53-835769 %s -S -o- \

clang/test/Driver/aarch64-fix-cortex-a53-835769.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
// RUN: %clang --target=aarch64-linux-androideabi %s -### 2>&1 \
99
// RUN: | FileCheck --check-prefix=CHECK-YES %s
10+
// RUN: %clang --target=aarch64-linux-androideabi -march=armv8.1-a %s -### 2>&1 \
11+
// RUN: | FileCheck --check-prefix=CHECK-DEF %s
1012

1113
// RUN: %clang --target=aarch64-fuchsia %s -### 2>&1 \
1214
// RUN: | FileCheck --check-prefix=CHECK-YES %s
15+
// RUN: %clang --target=aarch64-fuchsia -march=armv8.1-a %s -### 2>&1 \
16+
// RUN: | FileCheck --check-prefix=CHECK-DEF %s
1317

1418
// RUN: %clang --target=aarch64-fuchsia -mcpu=cortex-a73 %s -### 2>&1 \
1519
// RUN: | FileCheck --check-prefix=CHECK-DEF %s

0 commit comments

Comments
 (0)