diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp --- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -95,6 +95,9 @@ return false; if (!onlyUsedByLifetimeMarkers(GEPI)) return false; + } else if (const AddrSpaceCastInst *ASCI = dyn_cast(U)) { + if (!onlyUsedByLifetimeMarkers(ASCI)) + return false; } else { return false; } diff --git a/llvm/test/Transforms/SROA/alloca_addrspace.ll b/llvm/test/Transforms/SROA/alloca_addrspace.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/SROA/alloca_addrspace.ll @@ -0,0 +1,21 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -sroa -S | FileCheck %s +; RUN: opt < %s -passes=sroa -S | FileCheck %s +; RUN: opt < %s -mem2reg -S | FileCheck %s +; RUN: opt < %s -passes=mem2reg -S | FileCheck %s + +; Do not crash ;) + +target datalayout = "e-p:64:64-p5:32:32-A5" + +define amdgpu_kernel void @addressspace_alloca() { +; CHECK-LABEL: @addressspace_alloca( +; CHECK-NEXT: ret void +; + %alloca = alloca i8, align 8, addrspace(5) + %cast = addrspacecast i8 addrspace(5)* %alloca to i8* + call void @llvm.lifetime.start.p0i8(i64 2, i8* %cast) + ret void +} + +declare void @llvm.lifetime.start.p0i8(i64 %size, i8* nocapture %ptr)