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

[AArch64] set AppleA14 architecture version to v8.4-a #92600

Merged
merged 6 commits into from
Jun 10, 2024

Conversation

tmatheson-arm
Copy link
Contributor

Putting this up for review to double check, because Wikipedia claims it is v8.5-a but I noticed the citation is... TargetParser.

@llvmbot
Copy link
Collaborator

llvmbot commented May 17, 2024

@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-backend-aarch64

Author: Tomas Matheson (tmatheson-arm)

Changes

Putting this up for review to double check, because Wikipedia claims it is v8.5-a but I noticed the citation is... TargetParser.


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

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64Processors.td (+1-1)
diff --git a/llvm/lib/Target/AArch64/AArch64Processors.td b/llvm/lib/Target/AArch64/AArch64Processors.td
index f2286ae17dba5..96422758bc618 100644
--- a/llvm/lib/Target/AArch64/AArch64Processors.td
+++ b/llvm/lib/Target/AArch64/AArch64Processors.td
@@ -718,7 +718,7 @@ def ProcessorFeatures {
   list<SubtargetFeature> AppleA13 = [HasV8_4aOps, FeatureCrypto, FeatureFPARMv8,
                                      FeatureNEON, FeaturePerfMon, FeatureFullFP16,
                                      FeatureFP16FML, FeatureSHA3];
-  list<SubtargetFeature> AppleA14 = [HasV8_4aOps, FeatureCrypto, FeatureFPARMv8,
+  list<SubtargetFeature> AppleA14 = [HasV8_5aOps, FeatureCrypto, FeatureFPARMv8,
                                      FeatureNEON, FeaturePerfMon, FeatureFRInt3264,
                                      FeatureSpecRestrict, FeatureSSBS, FeatureSB,
                                      FeaturePredRes, FeatureCacheDeepPersist,

@AreaZR
Copy link
Contributor

AreaZR commented May 18, 2024

Apple's Apple Silicon Optimization Guide indeed says it is 8.5

@AreaZR
Copy link
Contributor

AreaZR commented May 18, 2024

@tmatheson-arm can you verify that the information in the guide matches what information is here regarding the chipset?

https://developer.apple.com/file/?file=applesiliconcpuoptimizationguide&agree=true

@AreaZR
Copy link
Contributor

AreaZR commented May 18, 2024

Said document also says M1 and A14 don't have the BTI feature that guards against execution of instructions that are not the intended target of a branch

@AreaZR
Copy link
Contributor

AreaZR commented May 18, 2024

Just checked. This is called: FeatureBranchTargetId, so we need to exclude it from A14, as it is the only thing from the 8.5 spec it doesn't support.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" debuginfo labels May 20, 2024
@tmatheson-arm
Copy link
Contributor Author

Thanks @AtariDreams for pointing that out. They do both seem to be "8.5 without BTI". I had a look at what current versions of clang/llvm do in this regard:

Current builds of clang set __ARM_FEATURE_BTI for these processors:

$ clang-19 ~/hello.c --target=aarch64 -march=armv8.4-a -E -dM -o - | rg __ARM_FEATURE_BTI

$ clang-19 ~/hello.c --target=aarch64 -march=armv8.5-a -E -dM -o - | rg __ARM_FEATURE_BTI
#define __ARM_FEATURE_BTI 1

$ clang-19 ~/hello.c --target=aarch64 -mcpu=apple-a14 -E -dM -o - | rg __ARM_FEATURE_BTI
#define __ARM_FEATURE_BTI 1

$ clang-19 ~/hello.c --target=aarch64 -mcpu=apple-m1 -E -dM -o - | rg __ARM_FEATURE_BTI
#define __ARM_FEATURE_BTI 1

They will also disassemble BTI instructions (rather than outputting "hint"):

$ clang-19 ~/hello.c --target=aarch64 -march=armv8.4-a -S -o - -mbranch-protection=pac-ret+bti | rg '(bti|hint)'
	hint	#34
$ clang-19 ~/hello.c --target=aarch64 -march=armv8.5-a -S -o - -mbranch-protection=pac-ret+bti | rg '(bti|hint)'
	bti	c
$ clang-19 ~/hello.c --target=aarch64 -mcpu=apple-a14 -S -o - -mbranch-protection=pac-ret+bti | rg '(bti|hint)'
	bti	c
$ clang-19 ~/hello.c --target=aarch64 -mcpu=apple-m1 -S -o - -mbranch-protection=pac-ret+bti | rg '(bti|hint)'
	bti	c

I don't think either of those is correct. Unfortunately in the backend we can't model negative features, so the best thing to do might be to model them as armv8.4-a and manually add all of the 8.5-a SubtargetFeatures except for BTI. I have updated the PR to do that.

@tmatheson-arm tmatheson-arm changed the title [AArch64] set AppleA14 architecture version to v8.5-a [AArch64] set AppleA14 architecture version to v8.4-a May 20, 2024
Copy link
Contributor

@jroelofs jroelofs left a comment

Choose a reason for hiding this comment

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

Correct, apple-m1 does not have BTI, but BTI is required for v8.5. My mistake.

@AreaZR
Copy link
Contributor

AreaZR commented May 21, 2024

Correct, apple-m1 does not have BTI, but BTI is required for v8.5. My mistake.

Not sure if you are involved in writing the optimization guide itself at Apple, but the way the chip is described as having 8.5 minus BTI is a bit confusing since that would technically make the chip not v8.5 @jroelofs

@AreaZR
Copy link
Contributor

AreaZR commented May 31, 2024

Any updates on this?

@ahmedbougacha
Copy link
Member

Correct, apple-m1 does not have BTI, but BTI is required for v8.5. My mistake.

Not sure if you are involved in writing the optimization guide itself at Apple, but the way the chip is described as having 8.5 minus BTI is a bit confusing since that would technically make the chip not v8.5 @jroelofs

Sure, it makes the chip "v8.5 (excluding FEAT_BTI)", which is what's written in the guide ;) The guide is intended as a human-readable guide for high-performance software writers, not as much as the almost-only-machine-readable specifications we're used to reading. The alternative would have been "v8.4a + all these features from v8.5" which is worse.

clang/lib/Basic/Targets/AArch64.cpp Show resolved Hide resolved
clang/test/Preprocessor/aarch64-target-features.c Outdated Show resolved Hide resolved
@AreaZR
Copy link
Contributor

AreaZR commented Jun 5, 2024

@jroelofs on a slight tangent, when do we get to add information on the M4 chip?

@AreaZR
Copy link
Contributor

AreaZR commented Jun 7, 2024

Is this ready to merge?

@AreaZR
Copy link
Contributor

AreaZR commented Jun 10, 2024

@jroelofs Can we please merge this?

@jroelofs
Copy link
Contributor

@jroelofs Can we please merge this?

It's up to @tmatheson-arm, it's their patch. I've already given an 'LGTM'.

@tmatheson-arm tmatheson-arm merged commit 39f09e8 into llvm:main Jun 10, 2024
7 checks passed
@tmatheson-arm tmatheson-arm deleted the a14_version_bump branch June 10, 2024 16:04
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Jun 12, 2024
According to the Apple Silicon Optimization Guide, these are 8.4 with
all features of 8.5 except BTI.
@HerrCai0907 HerrCai0907 mentioned this pull request Jun 13, 2024
@jroelofs
Copy link
Contributor

@jroelofs on a slight tangent, when do we get to add information on the M4 chip?

#95478

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category debuginfo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants