mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-18 22:38:56 +00:00
Implement Regression/Transforms/InstCombine/getelementptr_cast.ll, which
occurs many times in crafty git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18273 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ef1ef8272b
commit
646641e02c
@ -3783,6 +3783,21 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
GEP.setOperand(0, X);
|
GEP.setOperand(0, X);
|
||||||
return &GEP;
|
return &GEP;
|
||||||
}
|
}
|
||||||
|
} else if (GEP.getNumOperands() == 2) {
|
||||||
|
// Transform things like:
|
||||||
|
// %t = getelementptr ubyte* cast ([2 x sbyte]* %str to ubyte*), uint %V
|
||||||
|
// into: %t1 = getelementptr [2 x sbyte*]* %str, int 0, uint %V; cast
|
||||||
|
Constant *X = CE->getOperand(0);
|
||||||
|
const Type *SrcElTy = cast<PointerType>(X->getType())->getElementType();
|
||||||
|
const Type *ResElTy =cast<PointerType>(CE->getType())->getElementType();
|
||||||
|
if (isa<ArrayType>(SrcElTy) &&
|
||||||
|
TD->getTypeSize(cast<ArrayType>(SrcElTy)->getElementType()) ==
|
||||||
|
TD->getTypeSize(ResElTy)) {
|
||||||
|
Value *V = InsertNewInstBefore(
|
||||||
|
new GetElementPtrInst(X, Constant::getNullValue(Type::IntTy),
|
||||||
|
GEP.getOperand(1), GEP.getName()), GEP);
|
||||||
|
return new CastInst(V, GEP.getType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user