Fix crash from r158529 on Bullet.

Dynamic GEPs created by SROA needed to insert extra "i32 0"
operands to index through structs and arrays to get to the
vector being indexed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158590 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper
2012-06-16 01:43:26 +00:00
parent e5c7bc65c3
commit 06e6c385cb
2 changed files with 65 additions and 1 deletions

View File

@ -2011,8 +2011,17 @@ void SROA::RewriteGEP(GetElementPtrInst *GEPI, AllocaInst *AI, uint64_t Offset,
uint64_t EltIdx = FindElementAndOffset(T, EltOffset, IdxTy);
NewArgs.push_back(ConstantInt::get(IdxTy, EltIdx));
}
if (NonConstantIdx)
if (NonConstantIdx) {
Type* GepTy = T;
// This GEP has a dynamic index. We need to add "i32 0" to index through
// any structs or arrays in the original type until we get to the vector
// to index.
while (!isa<VectorType>(GepTy)) {
NewArgs.push_back(Constant::getNullValue(i32Ty));
GepTy = cast<CompositeType>(GepTy)->getTypeAtIndex(0U);
}
NewArgs.push_back(NonConstantIdx);
}
Instruction *Val = NewElts[Idx];
if (NewArgs.size() > 1) {
Val = GetElementPtrInst::CreateInBounds(Val, NewArgs, "", GEPI);