Skip to content

Commit

Permalink
[IR] Deprecate GetElementPtrInst::CreateInBounds without element type
Browse files Browse the repository at this point in the history
This API is not compatible with opaque pointers, the method
accepting an explicit pointer element type should be used instead.

Thankfully there were few in-tree users. The BPF case still ends
up using the pointer element type for now and needs something like
D105407 to avoid doing so.
  • Loading branch information
nikic committed Jul 4, 2021
1 parent 287d39d commit a213f73
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
20 changes: 10 additions & 10 deletions llvm/include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,15 +987,15 @@ class GetElementPtrInst : public Instruction {
NameStr, InsertAtEnd);
}

/// Create an "inbounds" getelementptr. See the documentation for the
/// "inbounds" flag in LangRef.html for details.
static GetElementPtrInst *CreateInBounds(Value *Ptr,
ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr){
LLVM_ATTRIBUTE_DEPRECATED(static GetElementPtrInst *CreateInBounds(
Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr = "",
Instruction *InsertBefore = nullptr),
"Use the version with explicit element type instead") {
return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
}

/// Create an "inbounds" getelementptr. See the documentation for the
/// "inbounds" flag in LangRef.html for details.
static GetElementPtrInst *
CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
Expand All @@ -1006,10 +1006,10 @@ class GetElementPtrInst : public Instruction {
return GEP;
}

static GetElementPtrInst *CreateInBounds(Value *Ptr,
ArrayRef<Value *> IdxList,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
LLVM_ATTRIBUTE_DEPRECATED(static GetElementPtrInst *CreateInBounds(
Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr,
BasicBlock *InsertAtEnd),
"Use the version with explicit element type instead") {
return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ void BPFAbstractMemberAccess::replaceWithGEP(std::vector<CallInst *> &CallList,
IdxList.push_back(Zero);
IdxList.push_back(Call->getArgOperand(GEPIndex));

auto *GEP = GetElementPtrInst::CreateInBounds(Call->getArgOperand(0),
IdxList, "", Call);
auto *GEP = GetElementPtrInst::CreateInBounds(
Call->getArgOperand(0)->getType()->getPointerElementType(),
Call->getArgOperand(0), IdxList, "", Call);
Call->replaceAllUsesWith(GEP);
Call->eraseFromParent();
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,9 @@ bool VectorCombine::foldSingleElementStore(Instruction &I) {
MemoryLocation::get(SI), AA))
return false;

Value *GEP = GetElementPtrInst::CreateInBounds(
SI->getPointerOperand(), {ConstantInt::get(Idx->getType(), 0), Idx});
Builder.Insert(GEP);
Value *GEP = Builder.CreateInBoundsGEP(
SI->getValueOperand()->getType(), SI->getPointerOperand(),
{ConstantInt::get(Idx->getType(), 0), Idx});
StoreInst *NSI = Builder.CreateStore(NewElement, GEP);
NSI->copyMetadata(*SI);
Align ScalarOpAlignment = computeAlignmentAfterScalarization(
Expand Down

0 comments on commit a213f73

Please sign in to comment.