mirror of
https://github.com/RPCSX/llvm.git
synced 2025-05-13 10:56:01 +00:00
Implement: Assembler/2004-01-11-getelementptrfolding.llx
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10759 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c9f75b5700
commit
952454dbff
@ -171,7 +171,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
|||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
LastTy = *I;
|
LastTy = *I;
|
||||||
|
|
||||||
if (LastTy && isa<ArrayType>(LastTy)) {
|
if ((LastTy && isa<ArrayType>(LastTy)) || IdxList[0]->isNullValue()) {
|
||||||
std::vector<Constant*> NewIndices;
|
std::vector<Constant*> NewIndices;
|
||||||
NewIndices.reserve(IdxList.size() + CE->getNumOperands());
|
NewIndices.reserve(IdxList.size() + CE->getNumOperands());
|
||||||
for (unsigned i = 1, e = CE->getNumOperands()-1; i != e; ++i)
|
for (unsigned i = 1, e = CE->getNumOperands()-1; i != e; ++i)
|
||||||
@ -179,11 +179,13 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
|||||||
|
|
||||||
// Add the last index of the source with the first index of the new GEP.
|
// Add the last index of the source with the first index of the new GEP.
|
||||||
// Make sure to handle the case when they are actually different types.
|
// Make sure to handle the case when they are actually different types.
|
||||||
Constant *Combined =
|
Constant *Combined = CE->getOperand(CE->getNumOperands()-1);
|
||||||
ConstantExpr::get(Instruction::Add,
|
if (!IdxList[0]->isNullValue()) // Otherwise it must be an array
|
||||||
ConstantExpr::getCast(IdxList[0], Type::LongTy),
|
Combined =
|
||||||
ConstantExpr::getCast(CE->getOperand(CE->getNumOperands()-1), Type::LongTy));
|
ConstantExpr::get(Instruction::Add,
|
||||||
|
ConstantExpr::getCast(IdxList[0], Type::LongTy),
|
||||||
|
ConstantExpr::getCast(Combined, Type::LongTy));
|
||||||
|
|
||||||
NewIndices.push_back(Combined);
|
NewIndices.push_back(Combined);
|
||||||
NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());
|
NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());
|
||||||
return ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices);
|
return ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user