diff options
author | Chris Lattner <sabre@nondot.org> | 2003-06-21 16:01:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-06-21 16:01:24 +0000 |
commit | f58544712bea73686383d35f0a13ad335f3ef58b (patch) | |
tree | 45cb582c974aa5ea3ec7e2738dfe2c62549c2a09 | |
parent | c901e8bd9ed46180607e66d8d189d21036e2cfd0 (diff) |
Generate code for LONG indexes to getelementptr instructions more efficiently
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6828 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/X86/InstSelectSimple.cpp | 26 | ||||
-rw-r--r-- | lib/Target/X86/X86ISelSimple.cpp | 26 |
2 files changed, 50 insertions, 2 deletions
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp index 3da937bda7..59c9657f70 100644 --- a/lib/Target/X86/InstSelectSimple.cpp +++ b/lib/Target/X86/InstSelectSimple.cpp @@ -1580,9 +1580,26 @@ void ISel::visitStoreInst(StoreInst &I) { /// visitCastInst - Here we have various kinds of copying with or without /// sign extension going on. void ISel::visitCastInst(CastInst &CI) { + Value *Op = CI.getOperand(0); + // If this is a cast from a 32-bit integer to a Long type, and the only uses + // of the case are GEP instructions, then the cast does not need to be + // generated explicitly, it will be folded into the GEP. + if (CI.getType() == Type::LongTy && + (Op->getType() == Type::IntTy || Op->getType() == Type::UIntTy)) { + bool AllUsesAreGEPs = true; + for (Value::use_iterator I = CI.use_begin(), E = CI.use_end(); I != E; ++I) + if (!isa<GetElementPtrInst>(*I)) { + AllUsesAreGEPs = false; + break; + } + + // No need to codegen this cast if all users are getelementptr instrs... + if (AllUsesAreGEPs) return; + } + unsigned DestReg = getReg(CI); MachineBasicBlock::iterator MI = BB->end(); - emitCastOperation(BB, MI, CI.getOperand(0), CI.getType(), DestReg); + emitCastOperation(BB, MI, Op, CI.getType(), DestReg); } /// emitCastOperation - Common code shared between visitCastInst and @@ -1937,6 +1954,13 @@ void ISel::emitGEPOperation(MachineBasicBlock *MBB, // time. assert(idx->getType() == Type::LongTy && "Bad GEP array index!"); + // Most GEP instructions use a [cast (int/uint) to LongTy] as their + // operand on X86. Handle this case directly now... + if (CastInst *CI = dyn_cast<CastInst>(idx)) + if (CI->getOperand(0)->getType() == Type::IntTy || + CI->getOperand(0)->getType() == Type::UIntTy) + idx = CI->getOperand(0); + // We want to add BaseReg to(idxReg * sizeof ElementType). First, we // must find the size of the pointed-to type (Not coincidentally, the next // type is the type of the elements in the array). diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp index 3da937bda7..59c9657f70 100644 --- a/lib/Target/X86/X86ISelSimple.cpp +++ b/lib/Target/X86/X86ISelSimple.cpp @@ -1580,9 +1580,26 @@ void ISel::visitStoreInst(StoreInst &I) { /// visitCastInst - Here we have various kinds of copying with or without /// sign extension going on. void ISel::visitCastInst(CastInst &CI) { + Value *Op = CI.getOperand(0); + // If this is a cast from a 32-bit integer to a Long type, and the only uses + // of the case are GEP instructions, then the cast does not need to be + // generated explicitly, it will be folded into the GEP. + if (CI.getType() == Type::LongTy && + (Op->getType() == Type::IntTy || Op->getType() == Type::UIntTy)) { + bool AllUsesAreGEPs = true; + for (Value::use_iterator I = CI.use_begin(), E = CI.use_end(); I != E; ++I) + if (!isa<GetElementPtrInst>(*I)) { + AllUsesAreGEPs = false; + break; + } + + // No need to codegen this cast if all users are getelementptr instrs... + if (AllUsesAreGEPs) return; + } + unsigned DestReg = getReg(CI); MachineBasicBlock::iterator MI = BB->end(); - emitCastOperation(BB, MI, CI.getOperand(0), CI.getType(), DestReg); + emitCastOperation(BB, MI, Op, CI.getType(), DestReg); } /// emitCastOperation - Common code shared between visitCastInst and @@ -1937,6 +1954,13 @@ void ISel::emitGEPOperation(MachineBasicBlock *MBB, // time. assert(idx->getType() == Type::LongTy && "Bad GEP array index!"); + // Most GEP instructions use a [cast (int/uint) to LongTy] as their + // operand on X86. Handle this case directly now... + if (CastInst *CI = dyn_cast<CastInst>(idx)) + if (CI->getOperand(0)->getType() == Type::IntTy || + CI->getOperand(0)->getType() == Type::UIntTy) + idx = CI->getOperand(0); + // We want to add BaseReg to(idxReg * sizeof ElementType). First, we // must find the size of the pointed-to type (Not coincidentally, the next // type is the type of the elements in the array). |