forked from OSchip/llvm-project
[InstCombine] improve variable name; NFC
llvm-svn: 328322
This commit is contained in:
parent
e3b44f9de6
commit
6de89ce3f7
|
@ -1976,19 +1976,17 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||||
/// into a gep of the original struct. This is important for SROA and alias
|
/// into a gep of the original struct. This is important for SROA and alias
|
||||||
/// analysis of unions. If "A" is also a bitcast, wait for A/X to be merged.
|
/// analysis of unions. If "A" is also a bitcast, wait for A/X to be merged.
|
||||||
if (BitCastInst *BCI = dyn_cast<BitCastInst>(PtrOp)) {
|
if (BitCastInst *BCI = dyn_cast<BitCastInst>(PtrOp)) {
|
||||||
Value *Operand = BCI->getOperand(0);
|
Value *SrcOp = BCI->getOperand(0);
|
||||||
PointerType *OpType = cast<PointerType>(Operand->getType());
|
PointerType *SrcType = cast<PointerType>(BCI->getSrcTy());
|
||||||
unsigned OffsetBits = DL.getIndexTypeSizeInBits(GEP.getType());
|
unsigned OffsetBits = DL.getIndexTypeSizeInBits(GEP.getType());
|
||||||
APInt Offset(OffsetBits, 0);
|
APInt Offset(OffsetBits, 0);
|
||||||
if (!isa<BitCastInst>(Operand) &&
|
if (!isa<BitCastInst>(SrcOp) && GEP.accumulateConstantOffset(DL, Offset)) {
|
||||||
GEP.accumulateConstantOffset(DL, Offset)) {
|
|
||||||
|
|
||||||
// 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.
|
||||||
if (!Offset) {
|
if (!Offset) {
|
||||||
// If the bitcast is of an allocation, and the allocation will be
|
// If the bitcast is of an allocation, and the allocation will be
|
||||||
// converted to match the type of the cast, don't touch this.
|
// converted to match the type of the cast, don't touch this.
|
||||||
if (isa<AllocaInst>(Operand) || isAllocationFn(Operand, &TLI)) {
|
if (isa<AllocaInst>(SrcOp) || isAllocationFn(SrcOp, &TLI)) {
|
||||||
// See if the bitcast simplifies, if so, don't nuke this GEP yet.
|
// See if the bitcast simplifies, if so, don't nuke this GEP yet.
|
||||||
if (Instruction *I = visitBitCast(*BCI)) {
|
if (Instruction *I = visitBitCast(*BCI)) {
|
||||||
if (I != BCI) {
|
if (I != BCI) {
|
||||||
|
@ -2000,20 +1998,20 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Operand->getType()->getPointerAddressSpace() != GEP.getAddressSpace())
|
if (SrcType->getPointerAddressSpace() != GEP.getAddressSpace())
|
||||||
return new AddrSpaceCastInst(Operand, GEP.getType());
|
return new AddrSpaceCastInst(SrcOp, GEP.getType());
|
||||||
return new BitCastInst(Operand, GEP.getType());
|
return new BitCastInst(SrcOp, GEP.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, if the offset is non-zero, we need to find out if there is a
|
// Otherwise, if the offset is non-zero, we need to find out if there is a
|
||||||
// field at Offset in 'A's type. If so, we can pull the cast through the
|
// field at Offset in 'A's type. If so, we can pull the cast through the
|
||||||
// GEP.
|
// GEP.
|
||||||
SmallVector<Value*, 8> NewIndices;
|
SmallVector<Value*, 8> NewIndices;
|
||||||
if (FindElementAtOffset(OpType, Offset.getSExtValue(), NewIndices)) {
|
if (FindElementAtOffset(SrcType, Offset.getSExtValue(), NewIndices)) {
|
||||||
Value *NGEP =
|
Value *NGEP =
|
||||||
GEP.isInBounds()
|
GEP.isInBounds()
|
||||||
? Builder.CreateInBoundsGEP(nullptr, Operand, NewIndices)
|
? Builder.CreateInBoundsGEP(nullptr, SrcOp, NewIndices)
|
||||||
: Builder.CreateGEP(nullptr, Operand, NewIndices);
|
: Builder.CreateGEP(nullptr, SrcOp, NewIndices);
|
||||||
|
|
||||||
if (NGEP->getType() == GEP.getType())
|
if (NGEP->getType() == GEP.getType())
|
||||||
return replaceInstUsesWith(GEP, NGEP);
|
return replaceInstUsesWith(GEP, NGEP);
|
||||||
|
|
Loading…
Reference in New Issue