[llvm] 1f2d10e - [NFC][IRBuilder] Reuse CreateGEP for helpers (#175979)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 14 08:57:13 PST 2026
Author: Nathan Gauër
Date: 2026-01-14T16:57:09Z
New Revision: 1f2d10e285f6f6cfeadac4b3c43f4f6833e612d9
URL: https://github.com/llvm/llvm-project/commit/1f2d10e285f6f6cfeadac4b3c43f4f6833e612d9
DIFF: https://github.com/llvm/llvm-project/commit/1f2d10e285f6f6cfeadac4b3c43f4f6833e612d9.diff
LOG: [NFC][IRBuilder] Reuse CreateGEP for helpers (#175979)
Many helper functions for single index GEP exist, but each implement the
same logic to then create the GetElementPtrInst. Refactoring to call a
single function.
This is some groundwork to prepare the SGEP implementation.
Added:
Modified:
llvm/include/llvm/IR/IRBuilder.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index bc35caabeb849..8c33f6efbe742 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1939,21 +1939,13 @@ class IRBuilderBase {
Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
const Twine &Name = "") {
Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
-
- if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::none()))
- return V;
-
- return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
+ return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
}
Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
const Twine &Name = "") {
Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
-
- if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::inBounds()))
- return V;
-
- return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
+ return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
}
Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
@@ -1963,11 +1955,7 @@ class IRBuilderBase {
ConstantInt::get(Type::getInt32Ty(Context), Idx0),
ConstantInt::get(Type::getInt32Ty(Context), Idx1)
};
-
- if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, NWFlags))
- return V;
-
- return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs, NWFlags), Name);
+ return CreateGEP(Ty, Ptr, Idxs, Name, NWFlags);
}
Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
@@ -1976,31 +1964,19 @@ class IRBuilderBase {
ConstantInt::get(Type::getInt32Ty(Context), Idx0),
ConstantInt::get(Type::getInt32Ty(Context), Idx1)
};
-
- if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::inBounds()))
- return V;
-
- return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
+ return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
}
Value *CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0,
const Twine &Name = "") {
Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
-
- if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::none()))
- return V;
-
- return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
+ return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::none());
}
Value *CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0,
const Twine &Name = "") {
Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
-
- if (auto *V = Folder.FoldGEP(Ty, Ptr, Idx, GEPNoWrapFlags::inBounds()))
- return V;
-
- return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
+ return CreateGEP(Ty, Ptr, Idx, Name, GEPNoWrapFlags::inBounds());
}
Value *CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1,
@@ -2009,11 +1985,7 @@ class IRBuilderBase {
ConstantInt::get(Type::getInt64Ty(Context), Idx0),
ConstantInt::get(Type::getInt64Ty(Context), Idx1)
};
-
- if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::none()))
- return V;
-
- return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
+ return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::none());
}
Value *CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0,
@@ -2022,11 +1994,7 @@ class IRBuilderBase {
ConstantInt::get(Type::getInt64Ty(Context), Idx0),
ConstantInt::get(Type::getInt64Ty(Context), Idx1)
};
-
- if (auto *V = Folder.FoldGEP(Ty, Ptr, Idxs, GEPNoWrapFlags::inBounds()))
- return V;
-
- return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
+ return CreateGEP(Ty, Ptr, Idxs, Name, GEPNoWrapFlags::inBounds());
}
Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
More information about the llvm-commits
mailing list