mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-17 04:24:00 +00:00
Move the "gep undef" -> "undef" transform from instcombine to
InstructionSimplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119970 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -691,13 +691,20 @@ Value *llvm::SimplifySelectInst(Value *CondVal, Value *TrueVal, Value *FalseVal,
|
|||||||
/// fold the result. If not, this returns null.
|
/// fold the result. If not, this returns null.
|
||||||
Value *llvm::SimplifyGEPInst(Value *const *Ops, unsigned NumOps,
|
Value *llvm::SimplifyGEPInst(Value *const *Ops, unsigned NumOps,
|
||||||
const TargetData *TD, const DominatorTree *) {
|
const TargetData *TD, const DominatorTree *) {
|
||||||
|
// The type of the GEP pointer operand.
|
||||||
|
const PointerType *PtrTy = cast<PointerType>(Ops[0]->getType());
|
||||||
|
|
||||||
// getelementptr P -> P.
|
// getelementptr P -> P.
|
||||||
if (NumOps == 1)
|
if (NumOps == 1)
|
||||||
return Ops[0];
|
return Ops[0];
|
||||||
|
|
||||||
// TODO.
|
if (isa<UndefValue>(Ops[0])) {
|
||||||
//if (isa<UndefValue>(Ops[0]))
|
// Compute the (pointer) type returned by the GEP instruction.
|
||||||
// return UndefValue::get(GEP.getType());
|
const Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, &Ops[1],
|
||||||
|
NumOps-1);
|
||||||
|
const Type *GEPTy = PointerType::get(LastType, PtrTy->getAddressSpace());
|
||||||
|
return UndefValue::get(GEPTy);
|
||||||
|
}
|
||||||
|
|
||||||
if (NumOps == 2) {
|
if (NumOps == 2) {
|
||||||
// getelementptr P, 0 -> P.
|
// getelementptr P, 0 -> P.
|
||||||
@ -706,7 +713,7 @@ Value *llvm::SimplifyGEPInst(Value *const *Ops, unsigned NumOps,
|
|||||||
return Ops[0];
|
return Ops[0];
|
||||||
// getelementptr P, N -> P if P points to a type of zero size.
|
// getelementptr P, N -> P if P points to a type of zero size.
|
||||||
if (TD) {
|
if (TD) {
|
||||||
const Type *Ty = cast<PointerType>(Ops[0]->getType())->getElementType();
|
const Type *Ty = PtrTy->getElementType();
|
||||||
if (Ty->isSized() && !TD->getTypeAllocSize(Ty))
|
if (Ty->isSized() && !TD->getTypeAllocSize(Ty))
|
||||||
return Ops[0];
|
return Ops[0];
|
||||||
}
|
}
|
||||||
|
@ -523,9 +523,6 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
|
|
||||||
Value *PtrOp = GEP.getOperand(0);
|
Value *PtrOp = GEP.getOperand(0);
|
||||||
|
|
||||||
if (isa<UndefValue>(GEP.getOperand(0)))
|
|
||||||
return ReplaceInstUsesWith(GEP, UndefValue::get(GEP.getType()));
|
|
||||||
|
|
||||||
// Eliminate unneeded casts for indices.
|
// Eliminate unneeded casts for indices.
|
||||||
if (TD) {
|
if (TD) {
|
||||||
bool MadeChange = false;
|
bool MadeChange = false;
|
||||||
|
Reference in New Issue
Block a user