mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
Implement testcase: Assembler/2003-08-20-ConstantExprGEP-Fold.llx
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7983 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
baefa33c26
commit
4b517a4654
@ -142,23 +142,27 @@ Constant *ConstantFoldGetElementPtr(const Constant *C,
|
|||||||
// FIXME: Implement folding of GEP constant exprs the same as instcombine does
|
// FIXME: Implement folding of GEP constant exprs the same as instcombine does
|
||||||
|
|
||||||
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
||||||
// Implement folding of:
|
// Combine Indices - If the source pointer to this getelementptr instruction
|
||||||
// void ()** getelementptr (%struct..TorRec* getelementptr
|
// is a getelementptr instruction, combine the indices of the two
|
||||||
// ([N x %struct..TorRec]* %llvm.global_dtors, long 0, long 0),
|
// getelementptr instructions into a single instruction.
|
||||||
// long 0, ubyte 1)
|
|
||||||
// Into:
|
|
||||||
// %struct..TorRec* getelementptr ([N x %struct..TorRec]*
|
|
||||||
// %llvm.global_dtors, long 0, long 0, ubyte 1)
|
|
||||||
//
|
//
|
||||||
if (CE->getOpcode() == Instruction::GetElementPtr)
|
if (CE->getOpcode() == Instruction::GetElementPtr) {
|
||||||
if (IdxList[0] == Constant::getNullValue(Type::LongTy)) {
|
if (CE->getOperand(CE->getNumOperands()-1)->getType() == Type::LongTy) {
|
||||||
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(); i != e; ++i)
|
for (unsigned i = 1, e = CE->getNumOperands()-1; i != e; ++i)
|
||||||
NewIndices.push_back(cast<Constant>(CE->getOperand(i)));
|
NewIndices.push_back(cast<Constant>(CE->getOperand(i)));
|
||||||
|
|
||||||
|
// Add the last index of the source with the first index of the new GEP.
|
||||||
|
Constant *Combined =
|
||||||
|
ConstantExpr::get(Instruction::Add, IdxList[0],
|
||||||
|
CE->getOperand(CE->getNumOperands()-1));
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Implement folding of:
|
// Implement folding of:
|
||||||
// int* getelementptr ([2 x int]* cast ([3 x int]* %X to [2 x int]*),
|
// int* getelementptr ([2 x int]* cast ([3 x int]* %X to [2 x int]*),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user