Skip to content

Conversation

gbaraldi
Copy link
Member

This implements @staticfloat solution for the LLVM error that appears on m1 builds #44107.
Current master is very brittle when building the m1 but this bug happens every time without the PR.
I tried debugging it quite a lot and LLVM DEBUG with arm lower call debug on doesn't show why it doesn't tail call so I have no idea why it fails, the bug was added by the purity PR as mentioned in the issue. I don't know if it has to do with the anonymous union but apple gives a warning for that

@DilumAluthge DilumAluthge added the backport 1.8 Change should be backported to release-1.8 label Feb 20, 2022
@giordano giordano added the system:apple silicon Affects Apple Silicon only (Darwin/ARM64) - e.g. M1 and other M-series chips label Feb 20, 2022
@giordano giordano linked an issue Feb 20, 2022 that may be closed by this pull request
Copy link
Contributor

@navidcy navidcy left a comment

Choose a reason for hiding this comment

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

This works on my MacBook Pro M1 Max.

@navidcy
Copy link
Contributor

navidcy commented Feb 20, 2022

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.0-DEV.35 (2022-02-20)
 _/ |\__'_|_|_|\__'_|  |  fix-m1-build/e102b5caaf (fork: 63 commits, 5 days)
|__/                   |

}
else {
// musttail support is very bad on ARM, PPC, PPC64 (as of LLVM 3.9)
// Known failures includes vararg (not needed here) and sret.
Copy link
Member

Choose a reason for hiding this comment

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

possible improvement?

Suggested change
// Known failures includes vararg (not needed here) and sret.
// Known failures includes vararg (not needed here) and sret.
ret->setTailCall();

Is this only M1, or all AArch64?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is m1 only. I wonder if it's this https://github.com/llvm/llvm-project/blob/d1cd64ffdd832220dbe1829c2f09b880be67be31/llvm/test/CodeGen/AArch64/GlobalISel/call-translator-musttail.ll, this is the only aarch64-apple exclusive thing related to musttail.

That might be a more robust solution for sure. Does doing the ccall as a tail call have some performance benefit?

@gbaraldi
Copy link
Member Author

I found what causes musttail to fail, it's that the stack arguments of the call don't fit into the save area for the callee. https://github.com/gbaraldi/llvm-project/blob/5be8ea4bd7b0d66214c22033a7fd298544e65027/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp#L5702-L5707. Not sure if it's something to be worried or not however.

@KristofferC
Copy link
Member

I'll merge this now since it fixes the build and we want this for 1.8-beta to be available on M1. #44279 (comment) can be discussed further and possible improvements can be done in future PRs.

@KristofferC KristofferC merged commit 629eb86 into JuliaLang:master Feb 23, 2022
KristofferC pushed a commit that referenced this pull request Feb 23, 2022
@ngam
Copy link

ngam commented Feb 23, 2022

@KristofferC, I recommend you keep track of @gbaraldi investigation somewhere to ensure the work doesn't get lost. Yes, merging it is fine and preferable --- thanks for that! But maybe open a new issue to keep track of all the development. (Maybe @gbaraldi can do that?)

Thanks a lot for the great work!!

@gbaraldi
Copy link
Member Author

gbaraldi commented Feb 23, 2022

I will open an issue to keep this is mind, this is is a consequence of the purity PR, there are some other issues related to it too so I might open a more general issue.

edit: issue opened #44314

@KristofferC KristofferC removed the backport 1.8 Change should be backported to release-1.8 label Feb 24, 2022
pchintalapudi pushed a commit to pchintalapudi/julia that referenced this pull request Feb 24, 2022
staticfloat pushed a commit to JuliaCI/julia-buildkite-testing that referenced this pull request Mar 2, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system:apple silicon Affects Apple Silicon only (Darwin/ARM64) - e.g. M1 and other M-series chips
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Building master branch crashes on Apple M1
7 participants