[PR #11] [MERGED] Fix GHC tail calls for arm64 #14

Closed
opened 2026-02-18 19:21:14 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/RPCS3/llvm-mirror/pull/11
Author: @sguo35
Created: 4/28/2022
Status: Merged
Merged: 5/5/2022
Merged by: @undefined

Base: masterHead: master


📝 Commits (1)

  • 94c3e89 Fix tail call guarantee setting for GHC on arm64 backend

📊 Changes

1 file changed (+2 additions, -1 deletions)

View changed files

📝 lib/Target/AArch64/AArch64ISelLowering.cpp (+2 -1)

📄 Description

ELF breaks on arm64 macOS due to some relocation issue and errors out in LLVM backend. Using MachO fails to generate trampolines. COFF seems to work if we remove the checks that limit it to Windows targets.

GHC tail call is also broken on arm64. No idea why this isn't an issue in GHC upstream but both mayTailCallThisCC and canGuaranteeTCO were returning false for GHC because GHC wasn't set as a case. This led to tail call returns silently failing because LLVM in arm64 is set to ignore prologue/epilogue for GHC but because LLVM thinks tail calls are disabled for GHC it uses branch and link to call functions leading to infinite loop on function return as ret tries to jump to lr but lr is the address of ret. I fixed this to match the x86 backend which does mark GHC as guaranteed TCO.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/RPCS3/llvm-mirror/pull/11 **Author:** [@sguo35](https://github.com/sguo35) **Created:** 4/28/2022 **Status:** ✅ Merged **Merged:** 5/5/2022 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`94c3e89`](https://github.com/RPCS3/llvm-mirror/commit/94c3e899d96a8858ce16014296fca48f5f0d63ec) Fix tail call guarantee setting for GHC on arm64 backend ### 📊 Changes **1 file changed** (+2 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `lib/Target/AArch64/AArch64ISelLowering.cpp` (+2 -1) </details> ### 📄 Description ~~ELF breaks on arm64 macOS due to some relocation issue and errors out in LLVM backend. Using MachO fails to generate trampolines. COFF seems to work if we remove the checks that limit it to Windows targets.~~ GHC tail call is also broken on arm64. No idea why this isn't an issue in GHC upstream but both `mayTailCallThisCC` and `canGuaranteeTCO` were returning false for GHC because GHC wasn't set as a case. This led to tail call returns silently failing because LLVM in arm64 is set to ignore prologue/epilogue for GHC but because LLVM thinks tail calls are disabled for GHC it uses branch and link to call functions leading to infinite loop on function return as `ret` tries to jump to `lr` but `lr` is the address of `ret`. I fixed this to match the x86 backend which does mark GHC as guaranteed TCO. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-18 19:21:14 -05:00
yindo closed this issue 2026-02-18 19:21:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: RPCS3/llvm-mirror#14