This is an archive of the discontinued LLVM Phabricator instance.

[NVPTX] Fix pointer type for short 32-bit pointers
ClosedPublic

Authored by asavonic on Jun 13 2022, 9:46 AM.

Details

Summary

Global variables used to be printed as u64/b64 even when -nvptx-short-ptr is set.

Diff Detail

Event Timeline

asavonic created this revision.Jun 13 2022, 9:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2022, 9:46 AM
asavonic requested review of this revision.Jun 13 2022, 9:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2022, 9:46 AM
asavonic added inline comments.Jun 13 2022, 10:05 AM
llvm/test/CodeGen/NVPTX/short-ptr.ll
19

Ptxas doesn't like global variables in local address space, so I will remove this case.
ptxas error: Module-scoped variables in .local state space are not allowed with ABI

asavonic updated this revision to Diff 436460.Jun 13 2022, 10:14 AM
  • Added ptxas RUN lines.
  • Removed test case with .local global variable because ptxas does not support them.
tra accepted this revision.Jun 13 2022, 11:32 AM

Good catch. Thank you for fixing this.

llvm/test/CodeGen/NVPTX/short-ptr.ll
19

We could use __const__ AS instead.

For testing local vars we should probably add a function with a local variable.

This revision is now accepted and ready to land.Jun 13 2022, 11:32 AM
asavonic added inline comments.Jun 15 2022, 3:21 PM
llvm/test/CodeGen/NVPTX/short-ptr.ll
19

For testing local vars we should probably add a function with a local variable.

Local variables are lowered as __local_depot followed by as a sequence of casts:

	mov.u64 	%SPL, __local_depot0;
	cvta.local.u64 	%SP, %SPL;
	add.u64 	%rd1, %SP, 0;
	{ .reg .b64 %tmp;
	  cvta.to.local.u64 	%tmp, %rd1;
	  cvt.u32.u64 	%r1, %tmp;             <--- r1 is our 32-bit local pointer
        }

So I added a test, but it fails because of a different issue:

declare void @use(i8 addrspace(5)* %local)
define void @test() {
  %v = alloca i8
  %cast = addrspacecast i8* %v to i8 addrspace(5)*
  call void @use(i8 addrspace(5)* %cast)
  ret void
}

PTX:
.extern .func use
(
	.param .b64 use_param_0   <--- pointer is 64-bit instead of 32
)
[...]
.param .b32 param0;
st.param.b32 [param0+0], %r1;    <--- call assumes a 32-bit pointer
call.uni 
use, 
(
param0
);

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

So either the call should pass the pointer as 64-bit, or the use function declaration is wrong. I'm not sure. Should --nvptx-short-ptr change function ABI?

tra added inline comments.Jun 16 2022, 10:54 AM
llvm/test/CodeGen/NVPTX/short-ptr.ll
13

BTW, the global variables themselves can all be in the global AS. we only care about the *type* of these variables which is what we're testing -- how we lower pointers in local/const/shared AS.

https://godbolt.org/z/7rx1jo18v

@s = local_unnamed_addr addrspace(1) global i32 addrspace(3)* null, align 8
@c = local_unnamed_addr addrspace(1) global i32 addrspace(4)* null, align 8
@l = local_unnamed_addr addrspace(1) global i32 addrspace(5)* null, align 8
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.