[llvm] 81bc732 - [IR][Verifier] Relax restriction on alloca address spaces

Andy Wingo via llvm-commits llvm-commits at lists.llvm.org
Fri May 21 02:55:15 PDT 2021


Author: Andy Wingo
Date: 2021-05-21T11:52:45+02:00
New Revision: 81bc732816107f6aff4fd61980f7b03cc92332b5

URL: https://github.com/llvm/llvm-project/commit/81bc732816107f6aff4fd61980f7b03cc92332b5
DIFF: https://github.com/llvm/llvm-project/commit/81bc732816107f6aff4fd61980f7b03cc92332b5.diff

LOG: [IR][Verifier] Relax restriction on alloca address spaces

In the WebAssembly target, we would like to allow alloca in two address
spaces.  The alloca instruction already has an address space argument,
but the verifier asserts that the address space of an alloca is the
default alloca address space from the datalayout.  This patch removes
this restriction.  Targets that would like to impose additional
restrictions should do so via target-specific verification passes.

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

Added: 
    

Modified: 
    llvm/docs/LangRef.rst
    llvm/lib/IR/Verifier.cpp
    llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll

Removed: 
    llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll
    llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll
    llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll
    llvm/test/CodeGen/AMDGPU/invalid-alloca.ll


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index a3b9c95655216..4c2de632ed3a4 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -9571,8 +9571,9 @@ Overview:
 
 The '``alloca``' instruction allocates memory on the stack frame of the
 currently executing function, to be automatically released when this
-function returns to its caller. The object is always allocated in the
-address space for allocas indicated in the datalayout.
+function returns to its caller.  If the address space is not explicitly
+specified, the object is allocated in the alloca address space from the
+:ref:`datalayout string<langref_datalayout>`.
 
 Arguments:
 """"""""""
@@ -9603,6 +9604,10 @@ the memory is reclaimed. Allocating zero bytes is legal, but the returned
 pointer may not be unique. The order in which memory is allocated (ie.,
 which way the stack grows) is not specified.
 
+Note that '``alloca``' outside of the alloca address space from the
+:ref:`datalayout string<langref_datalayout>` is meaningful only if the
+target has assigned it a semantics.
+
 If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`,
 the returned object is initially dead.
 See :ref:`llvm.lifetime.start <int_lifestart>` and

diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 7eea7116b999c..fb5c1a3088b92 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3811,11 +3811,6 @@ void Verifier::verifySwiftErrorValue(const Value *SwiftErrorVal) {
 
 void Verifier::visitAllocaInst(AllocaInst &AI) {
   SmallPtrSet<Type*, 4> Visited;
-  PointerType *PTy = AI.getType();
-  // TODO: Relax this restriction?
-  Assert(PTy->getAddressSpace() == DL.getAllocaAddrSpace(),
-         "Allocation instruction pointer not in the stack address space!",
-         &AI);
   Assert(AI.getAllocatedType()->isSized(&Visited),
          "Cannot allocate unsized type", &AI);
   Assert(AI.getArraySize()->getType()->isIntegerTy(),

diff  --git a/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll b/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll
deleted file mode 100644
index 3ab5890a1441a..0000000000000
--- a/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll
+++ /dev/null
@@ -1,11 +0,0 @@
-; RUN: not llvm-as < %s 2>&1 | FileCheck %s
-
-target datalayout = "A1"
-
-; CHECK: Allocation instruction pointer not in the stack address space!
-; CHECK-NEXT:  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2)
-
-define void @use_alloca() {
-  %alloca_scalar_no_align = alloca i32, addrspace(2)
-  ret void
-}

diff  --git a/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll b/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll
deleted file mode 100644
index 9f1b91aae6164..0000000000000
--- a/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll
+++ /dev/null
@@ -1,11 +0,0 @@
-; RUN: not llvm-as < %s 2>&1 | FileCheck %s
-
-target datalayout = "A1"
-
-; CHECK: Allocation instruction pointer not in the stack address space!
-; CHECK-NEXT:  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2)
-
-define void @use_alloca() {
-  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2)
-  ret void
-}

diff  --git a/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll b/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll
deleted file mode 100644
index 1e9d3cb959ce3..0000000000000
--- a/llvm/test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll
+++ /dev/null
@@ -1,13 +0,0 @@
-; RUN: not llvm-as < %s 2>&1 | FileCheck %s
-
-target datalayout = "A1"
-
-; CHECK: Allocation instruction pointer not in the stack address space!
-; CHECK-NEXT:  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2), !foo !0
-
-define void @use_alloca() {
-  %alloca_scalar_no_align = alloca i32, align 4, addrspace(2), !foo !0
-  ret void
-}
-
-!0 = !{}

diff  --git a/llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll b/llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll
index 01446dfb65356..f2d401675bd01 100644
--- a/llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll
+++ b/llvm/test/Assembler/drop-debug-info-nonzero-alloca.ll
@@ -1,7 +1,7 @@
-; RUN: llvm-as < %s -o %t.bc -data-layout=A5 2>&1 | FileCheck -check-prefixes=ALL,AS %s
-; RUN: llvm-dis < %t.bc | FileCheck -check-prefixes=ALL,DIS %s
-; RUN: opt < %s -S -data-layout=A5 2>&1 | FileCheck -check-prefixes=ALL,AS %s
-; RUN: opt < %t.bc -S | FileCheck -check-prefixes=ALL,DIS %s
+; RUN: llvm-as < %s -o %t.bc -data-layout=A5 2>&1 | FileCheck -check-prefixes=AS %s
+; RUN: llvm-dis < %t.bc | FileCheck -check-prefixes=DIS %s
+; RUN: opt < %s -S -data-layout=A5 2>&1 | FileCheck -check-prefixes=AS %s
+; RUN: opt < %t.bc -S | FileCheck -check-prefixes=DIS %s
 
 define void @foo() {
 entry:
@@ -12,7 +12,6 @@ entry:
       metadata i8* undef,
       metadata !DILocalVariable(scope: !1),
       metadata !DIExpression())
-; ALL-NOT: Allocation instruction pointer not in the stack address space!
 ; AS: llvm.dbg.value intrinsic requires a !dbg attachment
 ; AS: warning: ignoring invalid debug info in <stdin>
 ret void

diff  --git a/llvm/test/CodeGen/AMDGPU/invalid-alloca.ll b/llvm/test/CodeGen/AMDGPU/invalid-alloca.ll
deleted file mode 100644
index dd1e568d2a239..0000000000000
--- a/llvm/test/CodeGen/AMDGPU/invalid-alloca.ll
+++ /dev/null
@@ -1,20 +0,0 @@
-; RUN: not llvm-as -data-layout=A5 < %s 2>&1 | FileCheck -check-prefixes=COMMON,AS %s
-; RUN: not llc -mtriple amdgcn-amd-amdhsa < %s 2>&1 | FileCheck -check-prefixes=COMMON,LLC %s
-; RUN: llvm-as < %s | not llc -mtriple amdgcn-amd-amdhsa 2>&1 | FileCheck -check-prefixes=MISMATCH %s
-; RUN: not opt -data-layout=A5 -S < %s 2>&1 | FileCheck -check-prefixes=COMMON,OPT %s
-; RUN: llvm-as < %s | not opt -data-layout=A5 2>&1 | FileCheck -check-prefixes=MISMATCH %s
-
-; AS: assembly parsed, but does not verify as correct!
-; COMMON: Allocation instruction pointer not in the stack address space!
-; COMMON:  %tmp = alloca i32
-; MISMATCH: Explicit load/store type does not match pointee type of pointer operand
-; LLC: error: {{.*}}input module cannot be verified
-; OPT: error: input module is broken!
-
-define amdgpu_kernel void @test() {
-  %tmp = alloca i32
-  %tmp2 = alloca i32*
-  store i32* %tmp, i32** %tmp2
-  ret void
-}
-


        


More information about the llvm-commits mailing list