Skip to content

Commit

Permalink
[InstCombine] Use CreateGEP() API (NFC)
Browse files Browse the repository at this point in the history
Use the IRBuilder API that accepts inbounds as a boolean parameter,
rather than using a ternary.
  • Loading branch information
nikic committed Apr 5, 2023
1 parent 1ef51e0 commit 53280db
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GEPOperator>(&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<GEPOperator>(&GEP))));
return nullptr;
}

Expand All @@ -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())
Expand Down Expand Up @@ -2126,13 +2120,10 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP,
}

if (!Indices.empty())
return isMergedGEPInBounds(*Src, *cast<GEPOperator>(&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<GEPOperator>(&GEP))));

return nullptr;
}
Expand Down

0 comments on commit 53280db

Please sign in to comment.