[NVPTX] Fix PR41651
authorMichael Liao <michael.hliao@gmail.com>
Tue, 30 Jul 2019 19:52:01 +0000 (19:52 +0000)
committerMichael Liao <michael.hliao@gmail.com>
Tue, 30 Jul 2019 19:52:01 +0000 (19:52 +0000)
Summary:
- Use the passed `DL` directly as retrieving data layout from CS by
  checking the called function is not reliable. Under indirect function
  call, there is no called function.

Subscribers: jholewinski, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65468

llvm-svn: 367349

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/test/CodeGen/NVPTX/bug41651.ll [new file with mode: 0644]

index ae1aa98..b3fb057 100644 (file)
@@ -1291,8 +1291,8 @@ std::string NVPTXTargetLowering::getPrototype(
       O << ".param .b" << size << " _";
     } else if (isa<PointerType>(retTy)) {
       O << ".param .b" << PtrVT.getSizeInBits() << " _";
-    } else if (retTy->isAggregateType() || retTy->isVectorTy() || retTy->isIntegerTy(128)) {
-      auto &DL = CS.getCalledFunction()->getParent()->getDataLayout();
+    } else if (retTy->isAggregateType() || retTy->isVectorTy() ||
+               retTy->isIntegerTy(128)) {
       O << ".param .align " << retAlignment << " .b8 _["
         << DL.getTypeAllocSize(retTy) << "]";
     } else {
diff --git a/llvm/test/CodeGen/NVPTX/bug41651.ll b/llvm/test/CodeGen/NVPTX/bug41651.ll
new file mode 100644 (file)
index 0000000..6039d39
--- /dev/null
@@ -0,0 +1,13 @@
+; RUN: llc -filetype=asm -o - %s | FileCheck %s
+target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
+target triple = "nvptx64-nvidia-cuda"
+
+%func = type { i32 (i32, i32)** }
+
+; CHECK: foo
+; CHECK: call
+; CHECK: ret
+define void @foo() {
+  %call = call %func undef(i32 0, i32 1)
+  ret void
+}