Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Driver][ARM] Change Android's NEON FPU hardcoding to "== 7" as it pessimizes future ArmV8 code #122969

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

Sharjeel-Khan
Copy link
Contributor

@Sharjeel-Khan Sharjeel-Khan commented Jan 14, 2025

Android hardcoded NEON FPU for ARM version ">=" 7. This hardcoding was pessimizing ARMv8 code as it was locking it to NEON FPU instead of something more powerful.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:ARM clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Jan 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2025

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Sharjeel Khan (Sharjeel-Khan)

Changes

Android hardcoded NEON FPU for armv7 that is now causing issues with 32-bit builds for armv8 on Android.


Full diff: https://github.com/llvm/llvm-project/pull/122969.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Arch/ARM.cpp (+1-1)
  • (modified) clang/test/Driver/arm-mfpu.c (+19)
diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index b8181ce6dc012a..2fb16d2e41320f 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -647,7 +647,7 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D,
     (void)getARMFPUFeatures(D, WaFPU->first, Args, WaFPU->second, Features);
   } else if (FPUArg) {
     FPUKind = getARMFPUFeatures(D, FPUArg, Args, FPUArg->getValue(), Features);
-  } else if (Triple.isAndroid() && getARMSubArchVersionNumber(Triple) >= 7) {
+  } else if (Triple.isAndroid() && getARMSubArchVersionNumber(Triple) == 7) {
     const char *AndroidFPU = "neon";
     FPUKind = llvm::ARM::parseFPU(AndroidFPU);
     if (!llvm::ARM::getFPUFeatures(FPUKind, Features))
diff --git a/clang/test/Driver/arm-mfpu.c b/clang/test/Driver/arm-mfpu.c
index 1b174be388124d..babfa16741ad70 100644
--- a/clang/test/Driver/arm-mfpu.c
+++ b/clang/test/Driver/arm-mfpu.c
@@ -409,6 +409,25 @@
 // CHECK-ARM7-ANDROID-FP-DEFAULT-NOT: "-target-feature" "+sha2"
 // CHECK-ARM7-ANDROID-FP-DEFAULT-NOT: "-target-feature" "+aes"
 
+// RUN: %clang -target armv8-linux-androideabi21 %s -### -c 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARM8-ANDROID-FP-DEFAULT %s
+// CHECK-ARM8-ANDROID-FP-DEFAULT-DAG: "-target-feature" "+soft-float-abi"
+// CHECK-ARM8-ANDROID-FP-DEFAULT-DAG: "-target-feature" "+vfp3"
+// CHECK-ARM8-ANDROID-FP-DEFAULT-DAG: "-target-feature" "+vfp4"
+// CHECK-ARM8-ANDROID-FP-DEFAULT-DAG: "-target-feature" "+fp-armv8"
+// CHECK-ARM8-ANDROID-FP-DEFAULT-DAG: "-target-feature" "+aes"
+// CHECK-ARM8-ANDROID-FP-DEFAULT-DAG: "-target-feature" "+sha2"
+// CHECK-ARM8-ANDROID-FP-DEFAULT-NOT: "-target-feature" "+neon"
+
+// RUN: %clang -target armv8-linux-android %s -### -c 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARM8-ANDROID-DEFAULT %s
+// CHECK-ARM8-ANDROID-DEFAULT-DAG: "-target-feature" "+vfp3"
+// CHECK-ARM8-ANDROID-DEFAULT-DAG: "-target-feature" "+vfp4"
+// CHECK-ARM8-ANDROID-DEFAULT-DAG: "-target-feature" "+fp-armv8"
+// CHECK-ARM8-ANDROID-DEFAULT-DAG: "-target-feature" "+aes"
+// CHECK-ARM8-ANDROID-DEFAULT-DAG: "-target-feature" "+sha2"
+// CHECK-ARM8-ANDROID-DEFAULT-NOT: "-target-feature" "+neon"
+
 // RUN: %clang -target armv7-linux-androideabi21 %s -mfpu=vfp3-d16 -### -c 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-ARM7-ANDROID-FP-D16 %s
 // CHECK-ARM7-ANDROID-FP-D16-NOT: "-target-feature" "+soft-float"

Copy link
Collaborator

@stephenhines stephenhines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I might add is a bit more context in the commit message that by accidentally using ">= 7" previously, we were pessimizing ARMv8 code in the future (locking it into just NEON FPU, instead of something more powerful).

@Sharjeel-Khan Sharjeel-Khan changed the title [Driver] Fix hardcoding of NEON FPU for armv8 [Driver][ARM] Fix hardcoding of NEON FPU for armv8 Jan 15, 2025
Android hardcoded NEON FPU for ARM version ">=" 7. This hardcoding was
pessimizing ARMv8 code as it was locking it to NEON FPU instead of
something more powerful.
@DavidSpickett
Copy link
Collaborator

Yeah, my first impression from the commit message was that you removed the check entirely.

@Sharjeel-Khan Sharjeel-Khan changed the title [Driver][ARM] Fix hardcoding of NEON FPU for armv8 [Driver][ARM] Change Android's NEON FPU hardcoding to "== 7" as it pessimizes future ArmV8 code Jan 15, 2025
@DavidSpickett
Copy link
Collaborator

Make sure to update the PR Description as this becomes the commit message when the squash and merge happens.

(yes, this is confusing but that's how llvm is set up)

But what I read makes sense thank you for rephrasing the commit message.

@Sharjeel-Khan
Copy link
Contributor Author

Thanks, I updated the PR description. Do you mind merging it @DavidSpickett? I still do not have commit access.

@stephenhines stephenhines merged commit e9255dd into llvm:main Jan 15, 2025
8 checks passed
@Sharjeel-Khan Sharjeel-Khan deleted the android-armv8-issue branch January 15, 2025 21:25
hubot pushed a commit to aosp-mirror/platform_bionic that referenced this pull request Feb 13, 2025
This reverts commit 3b3b356.

Reason for revert: This test was disabled because it was failing on arm32 due to a bad hardcoding. We fixed the hardcoding in llvm/llvm-project#122969 and cherry-picked it in aosp/3453341 so the change is in clang-r547379. We can revert this CL and re-enable the test.

Bug: 369186774
Change-Id: I2cf8ec2ef25fdea134ce8e39c5fdba34c04fc524
Test: Presubmit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:ARM clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants