From c38fa7c01403a8116b12d719e977acfc61417041 Mon Sep 17 00:00:00 2001 From: Andrew Savonichev Date: Tue, 15 Nov 2022 21:39:34 +0300 Subject: [PATCH] [NVPTX] Fix pointer type for short 32-bit pointers Global variables used to be printed as u64/b64 even when -nvptx-short-ptr is set. Differential Revision: https://reviews.llvm.org/D127668 --- llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 8 ++++++-- llvm/test/CodeGen/NVPTX/short-ptr.ll | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 llvm/test/CodeGen/NVPTX/short-ptr.ll diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index 5b0bf57a48f84..f3a49fb683d60 100644 --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -1365,8 +1365,11 @@ NVPTXAsmPrinter::getPTXFundamentalTypeStr(Type *Ty, bool useB4PTR) const { return "f32"; case Type::DoubleTyID: return "f64"; - case Type::PointerTyID: - if (static_cast(TM).is64Bit()) + case Type::PointerTyID: { + unsigned PtrSize = TM.getPointerSizeInBits(Ty->getPointerAddressSpace()); + assert((PtrSize == 64 || PtrSize == 32) && "Unexpected pointer size"); + + if (PtrSize == 64) if (useB4PTR) return "b64"; else @@ -1375,6 +1378,7 @@ NVPTXAsmPrinter::getPTXFundamentalTypeStr(Type *Ty, bool useB4PTR) const { return "b32"; else return "u32"; + } default: break; } diff --git a/llvm/test/CodeGen/NVPTX/short-ptr.ll b/llvm/test/CodeGen/NVPTX/short-ptr.ll new file mode 100644 index 0000000000000..243c0c1847889 --- /dev/null +++ b/llvm/test/CodeGen/NVPTX/short-ptr.ll @@ -0,0 +1,17 @@ +; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s --check-prefix CHECK-DEFAULT +; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s --check-prefix CHECK-DEFAULT-32 +; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -nvptx-short-ptr | FileCheck %s --check-prefixes CHECK-SHORT-SHARED,CHECK-SHORT-CONST + +; RUN: %if ptxas %{ llc < %s -march=nvptx -mcpu=sm_20 | %ptxas-verify %} +; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 | %ptxas-verify %} +; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 -nvptx-short-ptr | %ptxas-verify %} + +; CHECK-DEFAULT: .visible .shared .align 8 .u64 s +; CHECK-DEFAULT-32: .visible .shared .align 8 .u32 s +; CHECK-SHORT-SHARED: .visible .shared .align 8 .u32 s +@s = local_unnamed_addr addrspace(3) global i32 addrspace(3)* null, align 8 + +; CHECK-DEFAULT: .visible .const .align 8 .u64 c +; CHECK-DEFAULT-32: .visible .const .align 8 .u32 c +; CHECK-SHORT-CONST: .visible .const .align 8 .u32 c +@c = local_unnamed_addr addrspace(4) global i32 addrspace(4)* null, align 8