replace usage of EmitGEPOffset() with TargetData::getIndexedOffset() when the GEP offset is known to be constant.

With this change, we avoid relying on the IR Builder to constant fold the operations.

No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158829 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nuno Lopes 2012-06-20 17:30:51 +00:00
parent 2769e93384
commit b47f3ea224
2 changed files with 6 additions and 8 deletions

View File

@ -1341,10 +1341,9 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) {
// non-type-safe code. // non-type-safe code.
if (TD && GEP->hasOneUse() && isa<BitCastInst>(GEP->getOperand(0)) && if (TD && GEP->hasOneUse() && isa<BitCastInst>(GEP->getOperand(0)) &&
GEP->hasAllConstantIndices()) { GEP->hasAllConstantIndices()) {
// We are guaranteed to get a constant from EmitGEPOffset. SmallVector<Value*, 8> Ops(GEP->idx_begin(), GEP->idx_end());
ConstantInt *OffsetV = cast<ConstantInt>(EmitGEPOffset(GEP)); int64_t Offset = TD->getIndexedOffset(GEP->getPointerOperandType(), Ops);
int64_t Offset = OffsetV->getSExtValue();
// Get the base pointer input of the bitcast, and the type it points to. // Get the base pointer input of the bitcast, and the type it points to.
Value *OrigBase = cast<BitCastInst>(GEP->getOperand(0))->getOperand(0); Value *OrigBase = cast<BitCastInst>(GEP->getOperand(0))->getOperand(0);
Type *GEPIdxTy = Type *GEPIdxTy =

View File

@ -1058,10 +1058,9 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
!isa<BitCastInst>(BCI->getOperand(0)) && GEP.hasAllConstantIndices() && !isa<BitCastInst>(BCI->getOperand(0)) && GEP.hasAllConstantIndices() &&
StrippedPtrTy->getAddressSpace() == GEP.getPointerAddressSpace()) { StrippedPtrTy->getAddressSpace() == GEP.getPointerAddressSpace()) {
// Determine how much the GEP moves the pointer. We are guaranteed to get // Determine how much the GEP moves the pointer.
// a constant back from EmitGEPOffset. SmallVector<Value*, 8> Ops(GEP.idx_begin(), GEP.idx_end());
ConstantInt *OffsetV = cast<ConstantInt>(EmitGEPOffset(&GEP)); int64_t Offset = TD->getIndexedOffset(GEP.getPointerOperandType(), Ops);
int64_t Offset = OffsetV->getSExtValue();
// If this GEP instruction doesn't move the pointer, just replace the GEP // If this GEP instruction doesn't move the pointer, just replace the GEP
// with a bitcast of the real input to the dest type. // with a bitcast of the real input to the dest type.