[PATCH] Use correct address space size GEP index in SROA

Matt Arsenault Matthew.Arsenault at amd.com
Thu Dec 12 13:56:55 PST 2013


  Split out removing default address space argument part, change test to modify one added by the other SROA patch

Hi chandlerc,

http://llvm-reviews.chandlerc.com/D1765

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1765?vs=4495&id=6066#toc

Files:
  lib/Transforms/Scalar/SROA.cpp
  test/Transforms/SROA/basictest.ll

Index: lib/Transforms/Scalar/SROA.cpp
===================================================================
--- lib/Transforms/Scalar/SROA.cpp
+++ lib/Transforms/Scalar/SROA.cpp
@@ -1215,6 +1215,9 @@
   if (Ty == TargetTy)
     return buildGEP(IRB, BasePtr, Indices);
 
+  // Pointer size to use for the indices.
+  unsigned PtrSize = DL.getPointerTypeSizeInBits(BasePtr->getType());
+
   // See if we can descend into a struct and locate a field with the correct
   // type.
   unsigned NumLayers = 0;
@@ -1222,11 +1225,13 @@
   do {
     if (ElementTy->isPointerTy())
       break;
-    if (SequentialType *SeqTy = dyn_cast<SequentialType>(ElementTy)) {
-      ElementTy = SeqTy->getElementType();
-      // Note that we use the default address space as this index is over an
-      // array or a vector, not a pointer.
-      Indices.push_back(IRB.getInt(APInt(DL.getPointerSizeInBits(0), 0)));
+
+    if (ArrayType *ArrayTy = dyn_cast<ArrayType>(ElementTy)) {
+      ElementTy = ArrayTy->getElementType();
+      Indices.push_back(IRB.getInt(APInt(PtrSize, 0)));
+    } else if (VectorType *VectorTy = dyn_cast<VectorType>(ElementTy)) {
+      ElementTy = VectorTy->getElementType();
+      Indices.push_back(IRB.getInt(APInt(32, 0)));
     } else if (StructType *STy = dyn_cast<StructType>(ElementTy)) {
       if (STy->element_begin() == STy->element_end())
         break; // Nothing left to descend into.
Index: test/Transforms/SROA/basictest.ll
===================================================================
--- test/Transforms/SROA/basictest.ll
+++ test/Transforms/SROA/basictest.ll
@@ -1160,7 +1160,7 @@
 ; CHECK: alloca [16 x i8], align 8
 
   %gep = getelementptr inbounds { [16 x i8] } addrspace(1)* %ptr, i64 -1
-; CHECK-NEXT: getelementptr inbounds { [16 x i8] } addrspace(1)* %ptr, i16 -1, i32 0, i64 0
+; CHECK-NEXT: getelementptr inbounds { [16 x i8] } addrspace(1)* %ptr, i16 -1, i32 0, i16 0
 
   %cast1 = bitcast { [16 x i8 ] } addrspace(1)* %gep to i8 addrspace(1)*
   %cast2 = bitcast { [16 x i8 ] }* %a to i8*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1765.2.patch
Type: text/x-patch
Size: 2038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131212/f72be879/attachment.bin>


More information about the llvm-commits mailing list