mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-23 20:57:21 +00:00
Implement test/Regression/Transforms/InstCombine/getelementptr_index.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12762 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ef09aab9ce
commit
cb69a4ed64
@ -2317,16 +2317,18 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
|
|
||||||
// Eliminate unneeded casts for indices.
|
// Eliminate unneeded casts for indices.
|
||||||
bool MadeChange = false;
|
bool MadeChange = false;
|
||||||
for (unsigned i = 1, e = GEP.getNumOperands(); i != e; ++i)
|
gep_type_iterator GTI = gep_type_begin(GEP);
|
||||||
|
for (unsigned i = 1, e = GEP.getNumOperands(); i != e; ++i, ++GTI)
|
||||||
|
if (isa<SequentialType>(*GTI)) {
|
||||||
if (CastInst *CI = dyn_cast<CastInst>(GEP.getOperand(i))) {
|
if (CastInst *CI = dyn_cast<CastInst>(GEP.getOperand(i))) {
|
||||||
Value *Src = CI->getOperand(0);
|
Value *Src = CI->getOperand(0);
|
||||||
const Type *SrcTy = Src->getType();
|
const Type *SrcTy = Src->getType();
|
||||||
const Type *DestTy = CI->getType();
|
const Type *DestTy = CI->getType();
|
||||||
if (Src->getType()->isInteger()) {
|
if (Src->getType()->isInteger()) {
|
||||||
if (SrcTy->getPrimitiveSize() == DestTy->getPrimitiveSize()) {
|
if (SrcTy->getPrimitiveSize() == DestTy->getPrimitiveSize()) {
|
||||||
// We can always eliminate a cast from ulong or long to the other. We
|
// We can always eliminate a cast from ulong or long to the other.
|
||||||
// can always eliminate a cast from uint to int or the other on 32-bit
|
// We can always eliminate a cast from uint to int or the other on
|
||||||
// pointer platforms.
|
// 32-bit pointer platforms.
|
||||||
if (DestTy->getPrimitiveSize() >= TD->getPointerSize()) {
|
if (DestTy->getPrimitiveSize() >= TD->getPointerSize()) {
|
||||||
MadeChange = true;
|
MadeChange = true;
|
||||||
GEP.setOperand(i, Src);
|
GEP.setOperand(i, Src);
|
||||||
@ -2344,6 +2346,19 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If we are using a wider index than needed for this platform, shrink it
|
||||||
|
// to what we need. If the incoming value needs a cast instruction,
|
||||||
|
// insert it. This explicit cast can make subsequent optimizations more
|
||||||
|
// obvious.
|
||||||
|
Value *Op = GEP.getOperand(i);
|
||||||
|
if (Op->getType()->getPrimitiveSize() > TD->getPointerSize())
|
||||||
|
if (!isa<Constant>(Op)) {
|
||||||
|
Op = InsertNewInstBefore(new CastInst(Op, TD->getIntPtrType(),
|
||||||
|
Op->getName()), GEP);
|
||||||
|
GEP.setOperand(i, Op);
|
||||||
|
MadeChange = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (MadeChange) return &GEP;
|
if (MadeChange) return &GEP;
|
||||||
|
|
||||||
// Combine Indices - If the source pointer to this getelementptr instruction
|
// Combine Indices - If the source pointer to this getelementptr instruction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user