summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-02-26 10:08:16 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-02-26 10:08:16 +0000
commitdfb2efd0da3fa1a88ae0f29cb7d856678351e1d6 (patch)
tree6bb4d39af135e0542bbbd8608b9bbab3c92b7f10 /llvm/lib/Transforms
parentca4caa8746bac8c4e5fb0a629cf02f66ad428603 (diff)
downloadbcm5719-llvm-dfb2efd0da3fa1a88ae0f29cb7d856678351e1d6.tar.gz
bcm5719-llvm-dfb2efd0da3fa1a88ae0f29cb7d856678351e1d6.zip
[SROA] Use the correct index integer size in GEPs through non-default
address spaces. This isn't really a correctness issue (the values are truncated) but its much cleaner. Patch by Matt Arsenault! llvm-svn: 202252
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/SROA.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index beb7387502b..a229107703c 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1290,6 +1290,9 @@ static Value *getNaturalGEPWithType(IRBuilderTy &IRB, const DataLayout &DL,
if (Ty == TargetTy)
return buildGEP(IRB, BasePtr, Indices, NamePrefix);
+ // 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;
@@ -1297,11 +1300,13 @@ static Value *getNaturalGEPWithType(IRBuilderTy &IRB, const DataLayout &DL,
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.getIntN(PtrSize, 0));
+ } else if (VectorType *VectorTy = dyn_cast<VectorType>(ElementTy)) {
+ ElementTy = VectorTy->getElementType();
+ Indices.push_back(IRB.getInt32(0));
} else if (StructType *STy = dyn_cast<StructType>(ElementTy)) {
if (STy->element_begin() == STy->element_end())
break; // Nothing left to descend into.
OpenPOWER on IntegriCloud