[llvm] [llvm] Pass insertion point directly to IRBuilder ctor (NFC) (PR #228019)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 03:12:28 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/228019

Pass insertion point directly to the ctor instead of calling
SetInsertPoint(). Also remove redundant SetCurrentDebugLocation()
calls, which SetInsertPoint() already does.

>From dbe7ca48dd5280fcd5c5dee08c1b335ce3d0bffd Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 1 Oct 2026 12:03:57 +0200
Subject: [PATCH] [llvm] Pass insertion point directly to IRBuilder ctor (NFC)

Pass insertion point directly to the ctor instead of calling
SetInsertPoint(). Also remove redundant SetCurrentDebugLocation()
calls, which SetInsertPoint() already does.
---
 llvm/lib/CodeGen/CodeGenPrepare.cpp           | 13 +++-----
 llvm/lib/CodeGen/WasmEHPrepare.cpp            |  3 +-
 llvm/lib/IR/AutoUpgrade.cpp                   |  3 +-
 .../Target/ARM/MVEGatherScatterLowering.cpp   | 17 +++-------
 .../WebAssemblyLowerEmscriptenEHSjLj.cpp      |  6 ++--
 .../WebAssemblyRefTypeMem2Local.cpp           |  3 +-
 .../lib/Transforms/Scalar/LoopSimplifyCFG.cpp |  3 +-
 .../Scalar/ScalarizeMaskedMemIntrin.cpp       | 33 ++++---------------
 8 files changed, 21 insertions(+), 60 deletions(-)

diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index b5dbebb0e49c8..8ad61486eb869 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2273,9 +2273,7 @@ static bool foldURemOfLoopIncrement(Instruction *Rem, const DataLayout *DL,
 
   // Create new remainder with induction variable.
   Type *Ty = Rem->getType();
-  IRBuilder<> Builder(Rem->getContext());
-
-  Builder.SetInsertPoint(LoopIncrPN);
+  IRBuilder<> Builder(LoopIncrPN);
   PHINode *NewRem = Builder.CreatePHI(Ty, 2);
 
   Builder.SetInsertPoint(cast<Instruction>(
@@ -2672,8 +2670,7 @@ static bool despeculateCountZeros(IntrinsicInst *CountZeros,
     FreshBBs.insert(EndBlock);
 
   // Set up a builder to create a compare, conditional branch, and PHI.
-  IRBuilder<> Builder(CountZeros->getContext());
-  Builder.SetInsertPoint(StartBlock->getTerminator());
+  IRBuilder<> Builder(StartBlock->getTerminator());
   Builder.SetCurrentDebugLocation(CountZeros->getDebugLoc());
 
   // Replace the unconditional branch that was created by the first split with
@@ -7947,8 +7944,7 @@ bool CodeGenPrepare::optimizeShuffleVectorInst(ShuffleVectorInst *SVI) {
       FixedVectorType::get(NewType, SVIVecType->getNumElements());
 
   // Create a bitcast (shuffle (insert (bitcast(..))))
-  IRBuilder<> Builder(SVI->getContext());
-  Builder.SetInsertPoint(SVI);
+  IRBuilder<> Builder(SVI);
   Value *BC1 = Builder.CreateBitCast(
       cast<Instruction>(SVI->getOperand(0))->getOperand(1), NewType);
   Value *Shuffle = Builder.CreateVectorSplat(NewVecType->getNumElements(), BC1);
@@ -8640,8 +8636,7 @@ static bool splitMergedValStore(StoreInst &SI, const DataLayout &DL,
     return false;
 
   // Start to split store.
-  IRBuilder<> Builder(SI.getContext());
-  Builder.SetInsertPoint(&SI);
+  IRBuilder<> Builder(&SI);
 
   // If LValue/HValue is a bitcast in another BB, create a new one in current
   // BB so it may be merged with the splitted stores by dag combiner.
diff --git a/llvm/lib/CodeGen/WasmEHPrepare.cpp b/llvm/lib/CodeGen/WasmEHPrepare.cpp
index 37cd2048dfc85..5efbe610ddd1e 100644
--- a/llvm/lib/CodeGen/WasmEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WasmEHPrepare.cpp
@@ -296,8 +296,7 @@ bool WasmEHPrepareImpl::prepareEHPads(Function &F) {
 void WasmEHPrepareImpl::prepareEHPad(BasicBlock *BB, bool NeedPersonality,
                                      unsigned Index) {
   assert(BB->isEHPad() && "BB is not an EHPad!");
-  IRBuilder<> IRB(BB->getContext());
-  IRB.SetInsertPoint(BB, BB->getFirstInsertionPt());
+  IRBuilder<> IRB(BB, BB->getFirstInsertionPt());
 
   auto *FPI = cast<FuncletPadInst>(BB->getFirstNonPHIIt());
   Instruction *GetExnCI = nullptr, *GetSelectorCI = nullptr;
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 43651371e730d..9d42f940becd8 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5762,10 +5762,9 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
     return;
 
   LLVMContext &C = CI->getContext();
-  IRBuilder<> Builder(C);
+  IRBuilder<> Builder(CI->getParent(), CI->getIterator());
   if (isa<FPMathOperator>(CI))
     Builder.setFastMathFlags(CI->getFastMathFlags());
-  Builder.SetInsertPoint(CI->getParent(), CI->getIterator());
 
   if (!NewFn) {
     // Get the Function's name.
diff --git a/llvm/lib/Target/ARM/MVEGatherScatterLowering.cpp b/llvm/lib/Target/ARM/MVEGatherScatterLowering.cpp
index ed95cba487e77..0f4b9e221e607 100644
--- a/llvm/lib/Target/ARM/MVEGatherScatterLowering.cpp
+++ b/llvm/lib/Target/ARM/MVEGatherScatterLowering.cpp
@@ -417,10 +417,7 @@ Instruction *MVEGatherScatterLowering::lowerGather(IntrinsicInst *I) {
   lookThroughBitcast(Ptr);
   assert(Ptr->getType()->isVectorTy() && "Unexpected pointer type");
 
-  IRBuilder<> Builder(I->getContext());
-  Builder.SetInsertPoint(I);
-  Builder.SetCurrentDebugLocation(I->getDebugLoc());
-
+  IRBuilder<> Builder(I);
   Instruction *Root = I;
 
   Instruction *Load = tryCreateIncrementingGatScat(I, Ptr, Builder);
@@ -592,10 +589,7 @@ Instruction *MVEGatherScatterLowering::lowerScatter(IntrinsicInst *I) {
   lookThroughBitcast(Ptr);
   assert(Ptr->getType()->isVectorTy() && "Unexpected pointer type");
 
-  IRBuilder<> Builder(I->getContext());
-  Builder.SetInsertPoint(I);
-  Builder.SetCurrentDebugLocation(I->getDebugLoc());
-
+  IRBuilder<> Builder(I);
   Instruction *Store = tryCreateIncrementingGatScat(I, Ptr, Builder);
   if (!Store)
     Store = tryCreateMaskedScatterOffset(I, Ptr, Builder);
@@ -1077,8 +1071,7 @@ bool MVEGatherScatterLowering::optimiseOffsets(Value *Offsets, BasicBlock *BB,
     IncrementingBlock = 1;
   }
 
-  IRBuilder<> Builder(BB->getContext());
-  Builder.SetInsertPoint(Phi);
+  IRBuilder<> Builder(Phi);
   Builder.SetCurrentDebugLocation(Offs->getDebugLoc());
 
   switch (Offs->getOpcode()) {
@@ -1216,9 +1209,7 @@ bool MVEGatherScatterLowering::optimiseAddress(Value *Address, BasicBlock *BB,
     return false;
   bool Changed = false;
   if (GEP->hasOneUse() && isa<GetElementPtrInst>(GEP->getPointerOperand())) {
-    IRBuilder<> Builder(GEP->getContext());
-    Builder.SetInsertPoint(GEP);
-    Builder.SetCurrentDebugLocation(GEP->getDebugLoc());
+    IRBuilder<> Builder(GEP);
     Value *Offsets;
     unsigned Scale;
     Value *Base = foldGEP(GEP, Offsets, Scale, Builder);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index 0ee7731f8e4f5..42918e39fae91 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -536,8 +536,7 @@ Value *WebAssemblyLowerEmscriptenEHSjLjImpl::wrapInvoke(CallBase *CI) {
   Module *M = CI->getModule();
   LLVMContext &C = M->getContext();
 
-  IRBuilder<> IRB(C);
-  IRB.SetInsertPoint(CI);
+  IRBuilder<> IRB(CI);
 
   // Pre-invoke
   // __THREW__ = 0;
@@ -730,11 +729,10 @@ void WebAssemblyLowerEmscriptenEHSjLjImpl::wrapTestSetjmp(
   Function *F = BB->getParent();
   Module *M = F->getParent();
   LLVMContext &C = M->getContext();
-  IRBuilder<> IRB(C);
+  IRBuilder<> IRB(BB);
   IRB.SetCurrentDebugLocation(DL);
 
   // if (%__THREW__.val != 0 & %__threwValue.val != 0)
-  IRB.SetInsertPoint(BB);
   BasicBlock *ThenBB1 = BasicBlock::Create(C, "if.then1", F);
   BasicBlock *ElseBB1 = BasicBlock::Create(C, "if.else1", F);
   BasicBlock *EndBB1 = BasicBlock::Create(C, "if.end", F);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyRefTypeMem2Local.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyRefTypeMem2Local.cpp
index 2c162308700af..2693084e59e00 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyRefTypeMem2Local.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyRefTypeMem2Local.cpp
@@ -66,8 +66,7 @@ FunctionPass *llvm::createWebAssemblyRefTypeMem2LocalLegacyPass() {
 void WebAssemblyRefTypeMem2LocalImpl::visitAllocaInst(AllocaInst &AI) {
   if (WebAssembly::isWebAssemblyReferenceType(AI.getAllocatedType())) {
     Changed = true;
-    IRBuilder<> IRB(AI.getContext());
-    IRB.SetInsertPoint(&AI);
+    IRBuilder<> IRB(&AI);
     auto *NewAI = IRB.CreateAlloca(AI.getAllocatedType(),
                                    WebAssembly::WASM_ADDRESS_SPACE_VAR, nullptr,
                                    AI.getName() + ".var");
diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
index 09d5b1d4ec676..998ab17a91a3f 100644
--- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
@@ -534,9 +534,8 @@ class ConstantTerminatorFoldingImpl {
       if (MSSAU && TheOnlySuccDuplicates > 1)
         MSSAU->removeDuplicatePhiEdgesBetween(BB, TheOnlySucc);
 
-      IRBuilder<> Builder(BB->getContext());
       Instruction *Term = BB->getTerminator();
-      Builder.SetInsertPoint(Term);
+      IRBuilder<> Builder(Term);
       Builder.CreateBr(TheOnlySucc);
       Term->eraseFromParent();
 
diff --git a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
index 432b079051d80..664031a581ed0 100644
--- a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
+++ b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
@@ -229,13 +229,10 @@ static void scalarizeMaskedLoad(const DataLayout &DL, bool HasBranchDivergence,
 
   Type *EltTy = VecType->getElementType();
 
-  IRBuilder<> Builder(CI->getContext());
   Instruction *InsertPt = CI;
+  IRBuilder<> Builder(InsertPt);
   BasicBlock *IfBlock = CI->getParent();
 
-  Builder.SetInsertPoint(InsertPt);
-  Builder.SetCurrentDebugLocation(CI->getDebugLoc());
-
   // Short-cut if the mask is all-true.
   if (isa<Constant>(Mask) && cast<Constant>(Mask)->isAllOnesValue()) {
     LoadInst *NewI = Builder.CreateAlignedLoad(VecType, Ptr, AlignVal);
@@ -417,10 +414,8 @@ static void scalarizeMaskedStore(const DataLayout &DL, bool HasBranchDivergence,
 
   Type *EltTy = VecType->getElementType();
 
-  IRBuilder<> Builder(CI->getContext());
   Instruction *InsertPt = CI;
-  Builder.SetInsertPoint(InsertPt);
-  Builder.SetCurrentDebugLocation(CI->getDebugLoc());
+  IRBuilder<> Builder(InsertPt);
 
   // Short-cut if the mask is all-true.
   if (isa<Constant>(Mask) && cast<Constant>(Mask)->isAllOnesValue()) {
@@ -589,14 +584,11 @@ static void scalarizeMaskedGather(const DataLayout &DL,
   auto *VecType = cast<FixedVectorType>(CI->getType());
   Type *EltTy = VecType->getElementType();
 
-  IRBuilder<> Builder(CI->getContext());
   Instruction *InsertPt = CI;
+  IRBuilder<> Builder(InsertPt);
   BasicBlock *IfBlock = CI->getParent();
-  Builder.SetInsertPoint(InsertPt);
   Align AlignVal = CI->getParamAlign(0).valueOrOne();
 
-  Builder.SetCurrentDebugLocation(CI->getDebugLoc());
-
   // The result vector
   Value *VResult = Src0;
   unsigned VectorWidth = VecType->getNumElements();
@@ -735,10 +727,8 @@ static void scalarizeMaskedScatter(const DataLayout &DL,
       isa<PointerType>(cast<VectorType>(Ptrs->getType())->getElementType()) &&
       "Vector of pointers is expected in masked scatter intrinsic");
 
-  IRBuilder<> Builder(CI->getContext());
   Instruction *InsertPt = CI;
-  Builder.SetInsertPoint(InsertPt);
-  Builder.SetCurrentDebugLocation(CI->getDebugLoc());
+  IRBuilder<> Builder(InsertPt);
 
   Align AlignVal = CI->getParamAlign(1).valueOrOne();
   unsigned VectorWidth = SrcFVTy->getNumElements();
@@ -836,13 +826,10 @@ static void scalarizeMaskedExpandLoad(const DataLayout &DL,
 
   Type *EltTy = VecType->getElementType();
 
-  IRBuilder<> Builder(CI->getContext());
   Instruction *InsertPt = CI;
+  IRBuilder<> Builder(InsertPt);
   BasicBlock *IfBlock = CI->getParent();
 
-  Builder.SetInsertPoint(InsertPt);
-  Builder.SetCurrentDebugLocation(CI->getDebugLoc());
-
   unsigned VectorWidth = VecType->getNumElements();
 
   // The result vector
@@ -982,13 +969,10 @@ static void scalarizeMaskedCompressStore(const DataLayout &DL,
 
   auto *VecType = cast<FixedVectorType>(Src->getType());
 
-  IRBuilder<> Builder(CI->getContext());
   Instruction *InsertPt = CI;
+  IRBuilder<> Builder(InsertPt);
   BasicBlock *IfBlock = CI->getParent();
 
-  Builder.SetInsertPoint(InsertPt);
-  Builder.SetCurrentDebugLocation(CI->getDebugLoc());
-
   Type *EltTy = VecType->getElementType();
 
   // Adjust alignment for the scalar instruction.
@@ -1108,11 +1092,8 @@ static void scalarizeMaskedVectorHistogram(const DataLayout &DL, CallInst *CI,
   auto *AddrType = cast<FixedVectorType>(Ptrs->getType());
   Type *EltTy = Inc->getType();
 
-  IRBuilder<> Builder(CI->getContext());
   Instruction *InsertPt = CI;
-  Builder.SetInsertPoint(InsertPt);
-
-  Builder.SetCurrentDebugLocation(CI->getDebugLoc());
+  IRBuilder<> Builder(InsertPt);
 
   // FIXME: Do we need to add an alignment parameter to the intrinsic?
   unsigned VectorWidth = AddrType->getNumElements();



More information about the llvm-commits mailing list