Index: include/llvm/IR/AutoUpgrade.h =================================================================== --- include/llvm/IR/AutoUpgrade.h +++ include/llvm/IR/AutoUpgrade.h @@ -70,7 +70,7 @@ /// Check the debug info version number, if it is out-dated, drop the debug /// info. Return true if module is modified. - bool UpgradeDebugInfo(Module &M); + bool UpgradeDebugInfo(Module &M, bool CheckAllocaAddrSpace = true); /// Check whether a string looks like an old loop attachment tag. inline bool mayBeOldLoopAttachmentTag(StringRef Name) { Index: include/llvm/IR/Verifier.h =================================================================== --- include/llvm/IR/Verifier.h +++ include/llvm/IR/Verifier.h @@ -97,7 +97,8 @@ /// error and instead *BrokenDebugInfo will be set to true. Debug /// info errors can be "recovered" from by stripping the debug info. bool verifyModule(const Module &M, raw_ostream *OS = nullptr, - bool *BrokenDebugInfo = nullptr); + bool *BrokenDebugInfo = nullptr, + bool CheckAllocaAddrSpace = true); FunctionPass *createVerifierPass(bool FatalErrors = true); Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -238,7 +238,7 @@ } if (UpgradeDebugInfo) - llvm::UpgradeDebugInfo(*M); + llvm::UpgradeDebugInfo(*M, false); UpgradeModuleFlags(*M); UpgradeSectionAttributes(*M); @@ -6174,14 +6174,7 @@ if (Size && !Size->getType()->isIntegerTy()) return Error(SizeLoc, "element count must have integer type"); - const DataLayout &DL = M->getDataLayout(); - unsigned AS = DL.getAllocaAddrSpace(); - if (AS != AddrSpace) { - // TODO: In the future it should be possible to specify addrspace per-alloca. - return Error(ASLoc, "address space must match datalayout"); - } - - AllocaInst *AI = new AllocaInst(Ty, AS, Size, Alignment); + AllocaInst *AI = new AllocaInst(Ty, AddrSpace, Size, Alignment); AI->setUsedWithInAlloca(IsInAlloca); AI->setSwiftError(IsSwiftError); Inst = AI; Index: lib/IR/AutoUpgrade.cpp =================================================================== --- lib/IR/AutoUpgrade.cpp +++ lib/IR/AutoUpgrade.cpp @@ -2415,11 +2415,11 @@ /// Check the debug info version number, if it is out-dated, drop the debug /// info. Return true if module is modified. -bool llvm::UpgradeDebugInfo(Module &M) { +bool llvm::UpgradeDebugInfo(Module &M, bool CheckAllocaAddrSpace) { unsigned Version = getDebugMetadataVersionFromModule(M); if (Version == DEBUG_METADATA_VERSION) { bool BrokenDebugInfo = false; - if (verifyModule(M, &llvm::errs(), &BrokenDebugInfo)) + if (verifyModule(M, &llvm::errs(), &BrokenDebugInfo, CheckAllocaAddrSpace)) report_fatal_error("Broken module found, compilation aborted!"); if (!BrokenDebugInfo) // Everything is ok. Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -305,14 +305,17 @@ TBAAVerifier TBAAVerifyHelper; + bool CheckAllocaAddrSpace; + void checkAtomicMemAccessSize(Type *Ty, const Instruction *I); public: explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError, - const Module &M) + const Module &M, bool ShouldCheckAllocaAddrSpace = true) : VerifierSupport(OS, M), LandingPadResultTy(nullptr), SawFrameEscape(false), TBAAVerifyHelper(this) { TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError; + CheckAllocaAddrSpace = ShouldCheckAllocaAddrSpace; } bool hasBrokenDebugInfo() const { return BrokenDebugInfo; } @@ -3202,8 +3205,10 @@ SmallPtrSet Visited; PointerType *PTy = AI.getType(); // TODO: Relax this restriction? - Assert(PTy->getAddressSpace() == DL.getAllocaAddrSpace(), - "Allocation instruction pointer not in the stack address space!", + Assert(!CheckAllocaAddrSpace || + PTy->getAddressSpace() == DL.getAllocaAddrSpace(), + "Allocation instruction pointer not in the dataLayout alloca address " + "space!", &AI); Assert(AI.getAllocatedType()->isSized(&Visited), "Cannot allocate unsized type", &AI); @@ -4616,10 +4621,11 @@ return !V.verify(F); } -bool llvm::verifyModule(const Module &M, raw_ostream *OS, - bool *BrokenDebugInfo) { +bool llvm::verifyModule(const Module &M, raw_ostream *OS, bool *BrokenDebugInfo, + bool CheckAllocaAddrSpace) { // Don't use a raw_null_ostream. Printing IR is expensive. - Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/!BrokenDebugInfo, M); + Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/!BrokenDebugInfo, M, + CheckAllocaAddrSpace); bool Broken = false; for (const Function &F : M) Index: test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll =================================================================== --- test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll +++ test/Assembler/datalayout-alloca-addrspace-mismatch-0.ll @@ -2,7 +2,9 @@ target datalayout = "A1" -; CHECK: :7:41: error: address space must match datalayout +; CHECK: Allocation instruction pointer not in the dataLayout alloca address space! +; CHECK-NEXT: %alloca_scalar_no_align = alloca i32, addrspace(2) + define void @use_alloca() { %alloca_scalar_no_align = alloca i32, addrspace(2) ret void Index: test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll =================================================================== --- test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll +++ test/Assembler/datalayout-alloca-addrspace-mismatch-1.ll @@ -2,7 +2,9 @@ target datalayout = "A1" -; CHECK: :7:50: error: address space must match datalayout +; CHECK: Allocation instruction pointer not in the dataLayout alloca 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 Index: test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll =================================================================== --- test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll +++ test/Assembler/datalayout-alloca-addrspace-mismatch-2.ll @@ -2,7 +2,9 @@ target datalayout = "A1" -; CHECK: :7:50: error: address space must match datalayout +; CHECK: Allocation instruction pointer not in the dataLayout alloca 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 Index: test/CodeGen/AMDGPU/fence-barrier.ll =================================================================== --- test/CodeGen/AMDGPU/fence-barrier.ll +++ test/CodeGen/AMDGPU/fence-barrier.ll @@ -1,4 +1,4 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx803 -enable-si-insert-waitcnts=1 -verify-machineinstrs < %s | FileCheck --check-prefix=GCN %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa-amdgiz -mcpu=gfx803 -enable-si-insert-waitcnts=1 -verify-machineinstrs < %s | FileCheck --check-prefix=GCN %s declare i8 addrspace(2)* @llvm.amdgcn.dispatch.ptr() declare i8 addrspace(2)* @llvm.amdgcn.implicitarg.ptr() @@ -16,8 +16,8 @@ ; GCN-NEXT: s_barrier ; GCN: flat_store_dword define amdgpu_kernel void @test_local(i32 addrspace(1)*) { - %2 = alloca i32 addrspace(1)*, align 4 - store i32 addrspace(1)* %0, i32 addrspace(1)** %2, align 4 + %2 = alloca i32 addrspace(1)*, align 4, addrspace(5) + store i32 addrspace(1)* %0, i32 addrspace(1)* addrspace(5)* %2, align 4 %3 = call i32 @llvm.amdgcn.workitem.id.x() %4 = zext i32 %3 to i64 %5 = icmp eq i64 %4, 0 @@ -32,7 +32,7 @@ call void @llvm.amdgcn.s.barrier() fence syncscope("workgroup") acquire %8 = load i32, i32 addrspace(3)* getelementptr inbounds ([1 x i32], [1 x i32] addrspace(3)* @test_local.temp, i64 0, i64 0), align 4 - %9 = load i32 addrspace(1)*, i32 addrspace(1)** %2, align 4 + %9 = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(5)* %2, align 4 %10 = call i8 addrspace(2)* @llvm.amdgcn.dispatch.ptr() %11 = call i32 @llvm.amdgcn.workitem.id.x() %12 = call i32 @llvm.amdgcn.workgroup.id.x() @@ -58,14 +58,14 @@ ; GCN: s_waitcnt vmcnt(0) lgkmcnt(0){{$}} ; GCN-NEXT: s_barrier define amdgpu_kernel void @test_global(i32 addrspace(1)*) { - %2 = alloca i32 addrspace(1)*, align 4 - %3 = alloca i32, align 4 - store i32 addrspace(1)* %0, i32 addrspace(1)** %2, align 4 - store i32 0, i32* %3, align 4 + %2 = alloca i32 addrspace(1)*, align 4, addrspace(5) + %3 = alloca i32, align 4, addrspace(5) + store i32 addrspace(1)* %0, i32 addrspace(1)* addrspace(5)* %2, align 4 + store i32 0, i32 addrspace(5)* %3, align 4 br label %4 ;