[llvm] r313282 - AMDGPU: Fix assert on alloca of array of struct

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 11:02:29 PDT 2017


Author: arsenm
Date: Thu Sep 14 11:02:29 2017
New Revision: 313282

URL: http://llvm.org/viewvc/llvm-project?rev=313282&view=rev
Log:
AMDGPU: Fix assert on alloca of array of struct

Modified:
    llvm/trunk/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
    llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-array-aggregate.ll

Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp?rev=313282&r1=313281&r2=313282&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp Thu Sep 14 11:02:29 2017
@@ -285,9 +285,9 @@ Value *AMDGPUPromoteAlloca::getWorkitemI
   return CI;
 }
 
-static VectorType *arrayTypeToVecType(Type *ArrayTy) {
-  return VectorType::get(ArrayTy->getArrayElementType(),
-                         ArrayTy->getArrayNumElements());
+static VectorType *arrayTypeToVecType(ArrayType *ArrayTy) {
+  return VectorType::get(ArrayTy->getElementType(),
+                         ArrayTy->getNumElements());
 }
 
 static Value *
@@ -346,10 +346,9 @@ static bool tryPromoteAllocaToVector(All
   // FIXME: We also reject alloca's of the form [ 2 x [ 2 x i32 ]] or equivalent. Potentially these
   // could also be promoted but we don't currently handle this case
   if (!AllocaTy ||
-      AllocaTy->getElementType()->isVectorTy() ||
-      AllocaTy->getElementType()->isArrayTy() ||
       AllocaTy->getNumElements() > 4 ||
-      AllocaTy->getNumElements() < 2) {
+      AllocaTy->getNumElements() < 2 ||
+      !VectorType::isValidElementType(AllocaTy->getElementType())) {
     DEBUG(dbgs() << "  Cannot convert type to vector\n");
     return false;
   }

Modified: llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-array-aggregate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-array-aggregate.ll?rev=313282&r1=313281&r2=313282&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-array-aggregate.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/promote-alloca-array-aggregate.ll Thu Sep 14 11:02:29 2017
@@ -11,6 +11,7 @@
 
 %Block = type { [1 x float], i32 }
 %gl_PerVertex = type { <4 x float>, float, [1 x float], [1 x float] }
+%struct = type { i32, i32 }
 
 @block = external addrspace(1) global %Block
 @pv = external addrspace(1) global %gl_PerVertex
@@ -129,3 +130,11 @@ define amdgpu_ps void @promote_double_ag
   store <4 x float> %tmp21, <4 x float> addrspace(1)* @frag_color
   ret void
 }
+
+; Don't crash on a type that isn't a valid vector element.
+; OPT-LABEL: @alloca_struct(
+define amdgpu_kernel void @alloca_struct() #0 {
+entry:
+  %alloca = alloca [2 x %struct], align 4
+  ret void
+}




More information about the llvm-commits mailing list