[llvm] [IR] Deprecate ConstantExpr::getGetElementPtr() (PR #227601)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 01:17:21 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

This deprecates various `ConstantExpr::getGetElementPtr()` overloads, in favor of either `ConstantExpr::getPtrAdd()`, or the overload taking a `DataLayout` (which converts GEP indices to ptradd).

Part of the ptradd migration.

---
Full diff: https://github.com/llvm/llvm-project/pull/227601.diff


5 Files Affected:

- (modified) llvm/include/llvm/IR/Constants.h (+10) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+2) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+2) 
- (modified) llvm/lib/IR/Constants.cpp (+2) 
- (modified) llvm/lib/IR/Core.cpp (+6) 


``````````diff
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index 65fa76c4ae126..db5ef5dfccac8 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -1465,11 +1465,14 @@ class ConstantExpr : public Constant {
                                 unsigned Flags = 0,
                                 Type *OnlyIfReducedTy = nullptr);
 
+  LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
+
   /// Getelementptr form.  Value* is only accepted for convenience;
   /// all elements must be Constants.
   ///
   /// \param InRange the inrange range if present or std::nullopt.
   /// \param OnlyIfReducedTy see \a getWithOperands() docs.
+  [[deprecated("Use getPtrAdd() or the overload accepting DataLayout instead")]]
   static Constant *
   getGetElementPtr(Type *Ty, Constant *C, ArrayRef<Constant *> IdxList,
                    GEPNoWrapFlags NW = GEPNoWrapFlags::none(),
@@ -1479,6 +1482,7 @@ class ConstantExpr : public Constant {
         Ty, C, ArrayRef((Value *const *)IdxList.data(), IdxList.size()), NW,
         InRange, OnlyIfReducedTy);
   }
+  [[deprecated("Use getPtrAdd() or the overload accepting DataLayout instead")]]
   static Constant *
   getGetElementPtr(Type *Ty, Constant *C, Constant *Idx,
                    GEPNoWrapFlags NW = GEPNoWrapFlags::none(),
@@ -1490,6 +1494,7 @@ class ConstantExpr : public Constant {
     return getGetElementPtr(Ty, C, cast<Value>(Idx), NW, InRange,
                             OnlyIfReducedTy);
   }
+  [[deprecated("Use getPtrAdd() or the overload accepting DataLayout instead")]]
   LLVM_ABI static Constant *
   getGetElementPtr(Type *Ty, Constant *C, ArrayRef<Value *> IdxList,
                    GEPNoWrapFlags NW = GEPNoWrapFlags::none(),
@@ -1520,10 +1525,12 @@ class ConstantExpr : public Constant {
 
   /// Create an "inbounds" getelementptr. See the documentation for the
   /// "inbounds" flag in LangRef.html for details.
+  [[deprecated("Use getPtrAdd() or the overload accepting DataLayout instead")]]
   static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C,
                                             ArrayRef<Constant *> IdxList) {
     return getGetElementPtr(Ty, C, IdxList, GEPNoWrapFlags::inBounds());
   }
+  [[deprecated("Use getPtrAdd() or the overload accepting DataLayout instead")]]
   static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C,
                                             Constant *Idx) {
     // This form of the function only exists to avoid ambiguous overload
@@ -1531,11 +1538,14 @@ class ConstantExpr : public Constant {
     // ArrayRef<Value *>.
     return getGetElementPtr(Ty, C, Idx, GEPNoWrapFlags::inBounds());
   }
+  [[deprecated("Use getPtrAdd() or the overload accepting DataLayout instead")]]
   static Constant *getInBoundsGetElementPtr(Type *Ty, Constant *C,
                                             ArrayRef<Value *> IdxList) {
     return getGetElementPtr(Ty, C, IdxList, GEPNoWrapFlags::inBounds());
   }
 
+  LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
+
   /// Create a getelementptr inbounds i8, ptr, offset constant expression.
   static Constant *getInBoundsPtrAdd(Constant *Ptr, Constant *Offset) {
     return getPtrAdd(Ptr, Offset, GEPNoWrapFlags::inBounds());
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index aaee06685fc2a..a793cc00812e3 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -4910,8 +4910,10 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
       if (!GetElementPtrInst::getIndexedType(Ty, Indices))
         return error(ID.Loc, "invalid getelementptr indices");
 
+      LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
       ID.ConstantVal =
           ConstantExpr::getGetElementPtr(Ty, Elts[0], Indices, NW, InRange);
+      LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
     } else if (Opc == Instruction::ShuffleVector) {
       if (Elts.size() != 3)
         return error(ID.Loc, "expected three operands to shufflevector");
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 4b338ae6237ec..af4015ea8ac68 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1765,9 +1765,11 @@ Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
           break;
         }
         case Instruction::GetElementPtr:
+          LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
           C = ConstantExpr::getGetElementPtr(
               BC->SrcElemTy, ConstOps[0], ArrayRef(ConstOps).drop_front(),
               toGEPNoWrapFlags(BC->Flags), BC->getInRange());
+          LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
           break;
         case Instruction::ExtractElement:
           C = ConstantExpr::getExtractElement(ConstOps[0], ConstOps[1]);
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 11183f2a4bf89..5c4d2e85e7fc3 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1745,9 +1745,11 @@ Constant *ConstantExpr::getWithOperands(ArrayRef<Constant *> Ops, Type *Ty,
   case Instruction::GetElementPtr: {
     auto *GEPO = cast<GEPOperator>(this);
     assert(SrcTy || (Ops[0]->getType() == getOperand(0)->getType()));
+    LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
     return ConstantExpr::getGetElementPtr(
         SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.slice(1),
         GEPO->getNoWrapFlags(), GEPO->getInRange(), OnlyIfReducedTy);
+    LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
   }
   default:
     assert(getNumOperands() == 2 && "Must be binary operator?");
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index c8fe01709383c..48422331912b9 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -1911,19 +1911,23 @@ LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
 
 LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
                            LLVMValueRef *ConstantIndices, unsigned NumIndices) {
+  LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
   ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
                                NumIndices);
   Constant *Val = unwrap<Constant>(ConstantVal);
   return wrap(ConstantExpr::getGetElementPtr(unwrap(Ty), Val, IdxList));
+  LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
 }
 
 LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
                                    LLVMValueRef *ConstantIndices,
                                    unsigned NumIndices) {
+  LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
   ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
                                NumIndices);
   Constant *Val = unwrap<Constant>(ConstantVal);
   return wrap(ConstantExpr::getInBoundsGetElementPtr(unwrap(Ty), Val, IdxList));
+  LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
 }
 
 LLVMValueRef LLVMConstGEPWithNoWrapFlags(LLVMTypeRef Ty,
@@ -1931,11 +1935,13 @@ LLVMValueRef LLVMConstGEPWithNoWrapFlags(LLVMTypeRef Ty,
                                          LLVMValueRef *ConstantIndices,
                                          unsigned NumIndices,
                                          LLVMGEPNoWrapFlags NoWrapFlags) {
+  LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
   ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
                                NumIndices);
   Constant *Val = unwrap<Constant>(ConstantVal);
   return wrap(ConstantExpr::getGetElementPtr(
       unwrap(Ty), Val, IdxList, mapFromLLVMGEPNoWrapFlags(NoWrapFlags)));
+  LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
 }
 
 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/227601


More information about the llvm-commits mailing list