This is an archive of the discontinued LLVM Phabricator instance.

[NVPTX] Fix pointer argument declaration for --nvptx-short-ptr
ClosedPublic

Authored by asavonic on Oct 11 2022, 7:23 AM.

Details

Summary

When --nvptx-short-ptr is set, local pointers are 32-bit on nvptx64 target.

Before this patch, arguments for a function declaration were always
emitted as b64 regardless of their address space, but they were correctly
set as b32 for the corresponding call instruction:

.extern .func test
(
 .param .b64 test_param_0
)
[...]
 .param .b32 param0;
 st.param.b32 [param0+0], %r1;
 call.uni test, (param0);

This is not supported:

ptxas: Type of argument does not match formal parameter
'test_param_0'

Now short pointers in a function declaration are emitted as b32 if
--nvptx-short-ptr is set.

This patch fixes the bug found in https://reviews.llvm.org/D127668#3587241.

Diff Detail

Event Timeline

asavonic created this revision.Oct 11 2022, 7:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2022, 7:23 AM
asavonic requested review of this revision.Oct 11 2022, 7:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2022, 7:23 AM
tra added inline comments.Oct 11 2022, 11:51 AM
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
1544

Should there be an else PTySizeInBits = TLI->getPointerTy(DL).getSizeInBits() ?

1592–1593

assert(PTySizeInBits) ?

asavonic updated this revision to Diff 467412.Oct 13 2022, 2:48 AM
  • Applied code review comments
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
1544

We only use PTySizeInBits when PTy is set. I've now changed the condition below to make it clear.

tra accepted this revision.Oct 13 2022, 10:25 AM

LGTM with a nit.

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
1594

The assertion should probably be moved to where we set PTySizeInBits, so it covers if(isKernelFunc) case, too.

This revision is now accepted and ready to land.Oct 13 2022, 10:25 AM
This revision was landed with ongoing or failed builds.Nov 15 2022, 10:52 AM
This revision was automatically updated to reflect the committed changes.