Skip to content

Conversation

Un1q32
Copy link
Contributor

@Un1q32 Un1q32 commented Jul 27, 2025

The iOS 2.x ABI had R9 as a reserved register, 3.0 made it available, but support for the 2.x ABI was never added to LLVM. We only use the 2.x ABI on armv6 since before 3.0 armv6 was the only architecture supported by iOS.

@llvmbot
Copy link
Member

llvmbot commented Jul 27, 2025

@llvm/pr-subscribers-backend-arm

Author: None (Un1q32)

Changes

The iOS 2.x ABI had R9 as a reserved register, 3.0 made it available, but support for the 2.x ABI was never added to LLVM. We only use the 2.x ABI on armv6 since before 3.0 armv6 was the only architecture supported by iOS.


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

1 Files Affected:

  • (modified) llvm/lib/Target/ARM/ARMSubtarget.cpp (+4-1)
diff --git a/llvm/lib/Target/ARM/ARMSubtarget.cpp b/llvm/lib/Target/ARM/ARMSubtarget.cpp
index 9f600e0c685ab..d6e226736ba66 100644
--- a/llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ b/llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -227,7 +227,10 @@ void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
       (Options.UnsafeFPMath || isTargetDarwin()))
     HasNEONForFP = true;
 
-  if (isRWPI())
+  if (isRWPI() ||
+      (isTargetIOS() &&
+       ARM::parseArch(TargetTriple.getArchName()) == ARM::ArchKind::ARMV6K &&
+       TargetTriple.isOSVersionLT(3, 0)))
     ReserveR9 = true;
 
   // If MVEVectorCostFactor is still 0 (has not been set to anything else), default it to 2

@jroelofs jroelofs requested a review from ahmedbougacha August 26, 2025 23:16
@Un1q32
Copy link
Contributor Author

Un1q32 commented Aug 27, 2025

Should probably be armv6 and armv6k actually.

@Un1q32
Copy link
Contributor Author

Un1q32 commented Aug 27, 2025

All armv6 iOS devices were armv6k, and clang -target armv6-apple-ios2 uses armv6k, but llc -mtriple=armv6-apple-ios2 doesn't so catching armv6 should help anyone running llc like that.

@Un1q32 Un1q32 changed the title Reserve R9 on armv6 iOS before 3.0 Reserve R9 on armv6 iOS 2.x Sep 8, 2025
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.

I haven't done the "archaeology" to check this, but it seems fine: IIUC the worst case fallout is that this hurts performance on a no-longer-supported platform, and best case is that it fixes this bug... so the tradeoff seems fine in light of that.

@Un1q32
Copy link
Contributor Author

Un1q32 commented Sep 29, 2025

I haven't done the "archaeology" to check this, but it seems fine: IIUC the worst case fallout is that this hurts performance on a no-longer-supported platform, and best case is that it fixes this bug... so the tradeoff seems fine in light of that.

I actually have the hardware to test with, and I've been carrying this patch for a while in my personal clang builds. Without it anything non-trivial segfaults, and with it everything works. I can probably find where this is done in the old Apple GCC sources and link that here.

@Un1q32
Copy link
Contributor Author

Un1q32 commented Oct 1, 2025

I don't have merge access btw so I would appreciate it if someone else could merge this for me.

@jroelofs jroelofs merged commit 133406e into llvm:main Oct 1, 2025
9 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
The iOS 2.x ABI had R9 as a reserved register, 3.0 made it available,
but support for the 2.x ABI was never added to LLVM. We only use the 2.x
ABI on armv6 since before 3.0 armv6 was the only architecture supported
by iOS.
@Un1q32 Un1q32 deleted the main branch October 4, 2025 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants