diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 7cae08df1171a..116e6b23a8a4d 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2043,13 +2043,11 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP, // If both GEP are constant-indexed, and cannot be merged in either way, // convert them to a GEP of i8. if (Src->hasAllConstantIndices()) - return isMergedGEPInBounds(*Src, *cast(&GEP)) - ? GetElementPtrInst::CreateInBounds( - Builder.getInt8Ty(), Src->getOperand(0), - Builder.getInt(OffsetOld), GEP.getName()) - : GetElementPtrInst::Create( - Builder.getInt8Ty(), Src->getOperand(0), - Builder.getInt(OffsetOld), GEP.getName()); + return replaceInstUsesWith( + GEP, Builder.CreateGEP( + Builder.getInt8Ty(), Src->getOperand(0), + Builder.getInt(OffsetOld), "", + isMergedGEPInBounds(*Src, *cast(&GEP)))); return nullptr; } @@ -2066,13 +2064,9 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP, IsInBounds &= Idx.isNonNegative() == ConstIndices[0].isNonNegative(); } - return IsInBounds - ? GetElementPtrInst::CreateInBounds(Src->getSourceElementType(), - Src->getOperand(0), Indices, - GEP.getName()) - : GetElementPtrInst::Create(Src->getSourceElementType(), - Src->getOperand(0), Indices, - GEP.getName()); + return replaceInstUsesWith( + GEP, Builder.CreateGEP(Src->getSourceElementType(), Src->getOperand(0), + Indices, "", IsInBounds)); } if (Src->getResultElementType() != GEP.getSourceElementType()) @@ -2126,13 +2120,10 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP, } if (!Indices.empty()) - return isMergedGEPInBounds(*Src, *cast(&GEP)) - ? GetElementPtrInst::CreateInBounds( - Src->getSourceElementType(), Src->getOperand(0), Indices, - GEP.getName()) - : GetElementPtrInst::Create(Src->getSourceElementType(), - Src->getOperand(0), Indices, - GEP.getName()); + return replaceInstUsesWith( + GEP, Builder.CreateGEP( + Src->getSourceElementType(), Src->getOperand(0), Indices, "", + isMergedGEPInBounds(*Src, *cast(&GEP)))); return nullptr; }