[llvm] r211906 - R600: Don't crash on unhandled instruction in promote alloca
Matt Arsenault
Matthew.Arsenault at amd.com
Fri Jun 27 14:50:47 PDT 2014
On 06/27/2014 02:46 PM, Reid Kleckner wrote:
> This generated a .s file in the source tree which is getting picked up
> in subsequent builds:
> http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/4876
>
> We need to commit this line for an hour and then roll it back in an
> hour or so to fix the bots:
> ; RUN: rm %S/private-memory-broken.s
>
Ok, I can do that. I was hoping the bots would eventually clean
themselves out
>
> On Fri, Jun 27, 2014 at 9:52 AM, Matt Arsenault
> <Matthew.Arsenault at amd.com <mailto:Matthew.Arsenault at amd.com>> wrote:
>
> Author: arsenm
> Date: Fri Jun 27 11:52:49 2014
> New Revision: 211906
>
> URL: http://llvm.org/viewvc/llvm-project?rev=211906&view=rev
> Log:
> R600: Don't crash on unhandled instruction in promote alloca
>
> Added:
> llvm/trunk/test/CodeGen/R600/private-memory-atomics.ll
> llvm/trunk/test/CodeGen/R600/private-memory-broken.ll
> Modified:
> llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp
> llvm/trunk/test/CodeGen/R600/private-memory.ll
>
> Modified: llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp?rev=211906&r1=211905&r2=211906&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp (original)
> +++ llvm/trunk/lib/Target/R600/AMDGPUPromoteAlloca.cpp Fri Jun 27
> 11:52:49 2014
> @@ -129,6 +129,22 @@ static Value* GEPToVectorIndex(GetElemen
> return GEP->getOperand(2);
> }
>
> +// Not an instruction handled below to turn into a vector.
> +//
> +// TODO: Check isTriviallyVectorizable for calls and handle other
> +// instructions.
> +static bool canVectorizeInst(Instruction *Inst) {
> + switch (Inst->getOpcode()) {
> + case Instruction::Load:
> + case Instruction::Store:
> + case Instruction::BitCast:
> + case Instruction::AddrSpaceCast:
> + return true;
> + default:
> + return false;
> + }
> +}
> +
> static bool tryPromoteAllocaToVector(AllocaInst *Alloca) {
> Type *AllocaTy = Alloca->getAllocatedType();
>
> @@ -149,6 +165,9 @@ static bool tryPromoteAllocaToVector(All
> for (User *AllocaUser : Alloca->users()) {
> GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(AllocaUser);
> if (!GEP) {
> + if (!canVectorizeInst(cast<Instruction>(AllocaUser)))
> + return false;
> +
> WorkList.push_back(AllocaUser);
> continue;
> }
> @@ -164,6 +183,9 @@ static bool tryPromoteAllocaToVector(All
>
> GEPVectorIdx[GEP] = Index;
> for (User *GEPUser : AllocaUser->users()) {
> + if (!canVectorizeInst(cast<Instruction>(GEPUser)))
> + return false;
> +
> WorkList.push_back(GEPUser);
> }
> }
> @@ -201,12 +223,12 @@ static bool tryPromoteAllocaToVector(All
> break;
> }
> case Instruction::BitCast:
> + case Instruction::AddrSpaceCast:
> break;
>
> default:
> Inst->dump();
> - llvm_unreachable("Do not know how to replace this instruction "
> - "with vector op");
> + llvm_unreachable("Inconsistency in instructions promotable
> to vector");
> }
> }
> return true;
>
> Added: llvm/trunk/test/CodeGen/R600/private-memory-atomics.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/R600/private-memory-atomics.ll?rev=211906&view=auto
> ==============================================================================
> --- llvm/trunk/test/CodeGen/R600/private-memory-atomics.ll (added)
> +++ llvm/trunk/test/CodeGen/R600/private-memory-atomics.ll Fri Jun
> 27 11:52:49 2014
> @@ -0,0 +1,31 @@
> +; RUN: llc -verify-machineinstrs -march=r600 -mcpu=SI < %s
> +
> +; This works because promote allocas pass replaces these with LDS
> atomics.
> +
> +; Private atomics have no real use, but at least shouldn't crash
> on it.
> +define void @atomicrmw_private(i32 addrspace(1)* %out, i32 %in)
> nounwind {
> +entry:
> + %tmp = alloca [2 x i32]
> + %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
> + %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
> + store i32 0, i32* %tmp1
> + store i32 1, i32* %tmp2
> + %tmp3 = getelementptr [2 x i32]* %tmp, i32 0, i32 %in
> + %tmp4 = atomicrmw add i32* %tmp3, i32 7 acq_rel
> + store i32 %tmp4, i32 addrspace(1)* %out
> + ret void
> +}
> +
> +define void @cmpxchg_private(i32 addrspace(1)* %out, i32 %in)
> nounwind {
> +entry:
> + %tmp = alloca [2 x i32]
> + %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
> + %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
> + store i32 0, i32* %tmp1
> + store i32 1, i32* %tmp2
> + %tmp3 = getelementptr [2 x i32]* %tmp, i32 0, i32 %in
> + %tmp4 = cmpxchg i32* %tmp3, i32 0, i32 1 acq_rel monotonic
> + %val = extractvalue { i32, i1 } %tmp4, 0
> + store i32 %val, i32 addrspace(1)* %out
> + ret void
> +}
>
> Added: llvm/trunk/test/CodeGen/R600/private-memory-broken.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/R600/private-memory-broken.ll?rev=211906&view=auto
> ==============================================================================
> --- llvm/trunk/test/CodeGen/R600/private-memory-broken.ll (added)
> +++ llvm/trunk/test/CodeGen/R600/private-memory-broken.ll Fri Jun
> 27 11:52:49 2014
> @@ -0,0 +1,20 @@
> +; RUN: not llc -verify-machineinstrs -march=r600 -mcpu=SI %s 2>&1
> | FileCheck %s
> +
> +; Make sure promote alloca pass doesn't crash
> +
> +; CHECK: unsupported call
> +
> +declare i32 @foo(i32*) nounwind
> +
> +define void @call_private(i32 addrspace(1)* %out, i32 %in) nounwind {
> +entry:
> + %tmp = alloca [2 x i32]
> + %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
> + %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
> + store i32 0, i32* %tmp1
> + store i32 1, i32* %tmp2
> + %tmp3 = getelementptr [2 x i32]* %tmp, i32 0, i32 %in
> + %val = call i32 @foo(i32* %tmp3) nounwind
> + store i32 %val, i32 addrspace(1)* %out
> + ret void
> +}
>
> Modified: llvm/trunk/test/CodeGen/R600/private-memory.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/R600/private-memory.ll?rev=211906&r1=211905&r2=211906&view=diff
> ==============================================================================
> --- llvm/trunk/test/CodeGen/R600/private-memory.ll (original)
> +++ llvm/trunk/test/CodeGen/R600/private-memory.ll Fri Jun 27
> 11:52:49 2014
> @@ -267,5 +267,19 @@ entry:
> %load = load i32* %gep2
> store i32 %load, i32 addrspace(1)* %out
> ret void
> +}
>
> +define void @select_private(i32 addrspace(1)* %out, i32 %in)
> nounwind {
> +entry:
> + %tmp = alloca [2 x i32]
> + %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
> + %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
> + store i32 0, i32* %tmp1
> + store i32 1, i32* %tmp2
> + %cmp = icmp eq i32 %in, 0
> + %sel = select i1 %cmp, i32* %tmp1, i32* %tmp2
> + %load = load i32* %sel
> + store i32 %load, i32 addrspace(1)* %out
> + ret void
> }
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140627/a48448b2/attachment.html>
More information about the llvm-commits
mailing list