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

[NVPTX] Incorrect alignment in call prototype for 'sprintf' function #100055

Closed
jhuber6 opened this issue Jul 23, 2024 · 4 comments · Fixed by #100131
Closed

[NVPTX] Incorrect alignment in call prototype for 'sprintf' function #100055

jhuber6 opened this issue Jul 23, 2024 · 4 comments · Fixed by #100131

Comments

@jhuber6
Copy link
Contributor

jhuber6 commented Jul 23, 2024

The NVPTX backend currently emits the incorrect alignment when trying to compile the sprintf function with LTO. It will emit errors like the following:

ptxas a.s, line 1509; error   : Alignment of argument does not match formal parameter '_'

Looking at the IR in https://godbolt.org/z/n9nK6ddxb I noticed that many of these _ function calls come from the main implementation. If this function is internalized, then these calls get an incorrect alignment of 16 as in the following:

prototype_82 : .callprototype (.param .b32 _) _ (.param .align 16 .b8 _[16], .param .b64 _);

If I make the indirect call instead have an alignment of 8, then it works just fine, i.e. This also happens if I manually remove the internal keyword from the function and thus make it .visible.

prototype_82 : .callprototype (.param .b32 _) _ (.param .align 8 .b8 _[16], .param .b64 _);

Any clue why this would cause issues? Since this is an indirect call it's not like there's a set prototype we need to adhere to. And I don't see why making the function .visible or not makes the alignment correct.

@jhuber6
Copy link
Contributor Author

jhuber6 commented Jul 23, 2024

@Artem-B Any ideas? I've disabled sprintf in the NVPTX tester for now.

@jhuber6
Copy link
Contributor Author

jhuber6 commented Jul 23, 2024

I have made a smaller reproducer https://godbolt.org/z/G7da6s6Yz. This will give the same error,

ptxas /tmp/indirect-3cf878.s, line 89; error   : Alignment of argument does not match formal parameter '_'

If the alignment is modified to be 1 instead it will work.

jhuber6 added a commit to jhuber6/llvm-project that referenced this issue Jul 23, 2024
Summary:
The NVPTX backend optimizes the ABI for functions that are internal,
however, this is not legal for indirect call prototypes. Previously, we
would modify the ABI on an aggregate byval type passed to an indirect
call prototype, which would make PTXAS error. This patch just passes the
function as a nullptr to force strict ABI compliance without
modification in the helper function.

Fixes llvm#100055
@jhuber6 jhuber6 added this to the LLVM 19.X Release milestone Jul 23, 2024
jhuber6 added a commit to jhuber6/llvm-project that referenced this issue Jul 23, 2024
Summary:
The NVPTX backend optimizes the ABI for functions that are internal,
however, this is not legal for indirect call prototypes. Previously, we
would modify the ABI on an aggregate byval type passed to an indirect
call prototype, which would make PTXAS error. This patch just passes the
function as a nullptr to force strict ABI compliance without
modification in the helper function.

Fixes llvm#100055
@jhuber6
Copy link
Contributor Author

jhuber6 commented Jul 23, 2024

/cherry-pick e0649a5

llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Jul 23, 2024
…vm#100131)

Summary:
The NVPTX backend optimizes the ABI for functions that are internal,
however, this is not legal for indirect call prototypes. Previously, we
would modify the ABI on an aggregate byval type passed to an indirect
call prototype, which would make PTXAS error. This patch just passes the
function as a nullptr to force strict ABI compliance without
modification in the helper function.

Fixes llvm#100055

(cherry picked from commit e0649a5)
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 23, 2024

/pull-request #100174

tru pushed a commit to llvmbot/llvm-project that referenced this issue Jul 24, 2024
…vm#100131)

Summary:
The NVPTX backend optimizes the ABI for functions that are internal,
however, this is not legal for indirect call prototypes. Previously, we
would modify the ABI on an aggregate byval type passed to an indirect
call prototype, which would make PTXAS error. This patch just passes the
function as a nullptr to force strict ABI compliance without
modification in the helper function.

Fixes llvm#100055

(cherry picked from commit e0649a5)
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
…00131)

Summary:
The NVPTX backend optimizes the ABI for functions that are internal,
however, this is not legal for indirect call prototypes. Previously, we
would modify the ABI on an aggregate byval type passed to an indirect
call prototype, which would make PTXAS error. This patch just passes the
function as a nullptr to force strict ABI compliance without
modification in the helper function.

Fixes #100055

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants