https://github.com/sfu2 created https://github.com/llvm/llvm-project/pull/174702

A set of cleanup for redundant implicit container copies. Fixed with const 
reference or move semantics.

ece18dcd0 [AMDGPU] replace copy with const reference (NFC)
699b110b4 [-Wunsafe-buffer-usage] Replace vector copy with reference (NFC)
12c1d6000 [AMDGPU] Replace copy with move semantics (NFC)
008555245 [InstCombine] Replace vector copy with move semantic (NFC)
21ada655d [CommandLine] Avoid vector copy for const argument (NFC)
afd48098f [LoongArch] Remove unnecessary vector copy (NFC)
bee971162 [TextAPI] Replace map copy with const reference (NFC)
fb44e3ea7 [BlockExtract] Avoid copy semantic for ctor (NFC)
8ab5df0a7 [LifetimeSafety] Avoid map copy for dump methods (NFC)

>From 8ab5df0a7b601296ec81ca73440ab8f8df405cc9 Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:25:17 +0000
Subject: [PATCH 1/9] [LifetimeSafety] Avoid map copy for dump methods (NFC)

---
 .../clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h      | 2 +-
 clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp             | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h 
b/clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h
index 8ad17db83499d..35b4224883cce 100644
--- a/clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h
+++ b/clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h
@@ -87,7 +87,7 @@ class LiveOriginsAnalysis {
 
   // Dump liveness values on all test points in the program.
   void dump(llvm::raw_ostream &OS,
-            llvm::StringMap<ProgramPoint> TestPoints) const;
+            const llvm::StringMap<ProgramPoint> &TestPoints) const;
 
 private:
   class Impl;
diff --git a/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp 
b/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
index f567cdc548ba7..fbbd402e77192 100644
--- a/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
@@ -165,7 +165,7 @@ class AnalysisImpl
 
   // Dump liveness values on all test points in the program.
   void dump(llvm::raw_ostream &OS,
-            llvm::StringMap<ProgramPoint> TestPoints) const {
+            const llvm::StringMap<ProgramPoint> &TestPoints) const {
     llvm::dbgs() << "==========================================\n";
     llvm::dbgs() << getAnalysisName() << " results:\n";
     llvm::dbgs() << "==========================================\n";
@@ -200,7 +200,7 @@ LivenessMap 
LiveOriginsAnalysis::getLiveOriginsAt(ProgramPoint P) const {
 }
 
 void LiveOriginsAnalysis::dump(llvm::raw_ostream &OS,
-                               llvm::StringMap<ProgramPoint> TestPoints) const 
{
+                               const llvm::StringMap<ProgramPoint> 
&TestPoints) const {
   PImpl->dump(OS, TestPoints);
 }
 } // namespace clang::lifetimes::internal

>From fb44e3ea7f5e2ef78b6461c237554f1df3c14cbc Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:25:33 +0000
Subject: [PATCH 2/9] [BlockExtract] Avoid copy semantic for ctor (NFC)

---
 llvm/lib/Transforms/IPO/BlockExtractor.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/IPO/BlockExtractor.cpp 
b/llvm/lib/Transforms/IPO/BlockExtractor.cpp
index 44913533030e3..a88ca1f3d6bd9 100644
--- a/llvm/lib/Transforms/IPO/BlockExtractor.cpp
+++ b/llvm/lib/Transforms/IPO/BlockExtractor.cpp
@@ -196,7 +196,7 @@ bool BlockExtractor::runOnModule(Module &M) {
 BlockExtractorPass::BlockExtractorPass(
     std::vector<std::vector<BasicBlock *>> &&GroupsOfBlocks,
     bool EraseFunctions)
-    : GroupsOfBlocks(GroupsOfBlocks), EraseFunctions(EraseFunctions) {}
+    : GroupsOfBlocks(std::move(GroupsOfBlocks)), 
EraseFunctions(EraseFunctions) {}
 
 PreservedAnalyses BlockExtractorPass::run(Module &M,
                                           ModuleAnalysisManager &AM) {

>From bee9711622d4e694bbd459f312c156b163a1684f Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:28:52 +0000
Subject: [PATCH 3/9] [TextAPI] Replace map copy with const reference (NFC)

---
 llvm/lib/TextAPI/TextStubV5.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/TextAPI/TextStubV5.cpp b/llvm/lib/TextAPI/TextStubV5.cpp
index f2687513bb854..de40d84f5e7a6 100644
--- a/llvm/lib/TextAPI/TextStubV5.cpp
+++ b/llvm/lib/TextAPI/TextStubV5.cpp
@@ -642,13 +642,13 @@ Expected<IFPtr> parseToInterfaceFile(const Object *File) {
   auto UmbrellasOrErr = getUmbrellaSection(File, Targets);
   if (!UmbrellasOrErr)
     return UmbrellasOrErr.takeError();
-  AttrToTargets Umbrellas = *UmbrellasOrErr;
+  const AttrToTargets &Umbrellas = *UmbrellasOrErr;
 
   auto ClientsOrErr =
       getLibSection(File, TBDKey::AllowableClients, TBDKey::Clients, Targets);
   if (!ClientsOrErr)
     return ClientsOrErr.takeError();
-  AttrToTargets Clients = *ClientsOrErr;
+  const AttrToTargets &Clients = *ClientsOrErr;
 
   auto RLOrErr =
       getLibSection(File, TBDKey::ReexportLibs, TBDKey::Names, Targets);

>From afd48098f99dc06457245c95a72480f10c37f951 Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:32:46 +0000
Subject: [PATCH 4/9] [LoongArch] Remove unnecessary vector copy (NFC)

---
 llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp 
b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
index 2ab2a98c9434c..4b5cba716c638 100644
--- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -276,7 +276,7 @@ void LoongArchAsmPrinter::emitJumpTableInfo() {
     return;
 
   unsigned Size = getDataLayout().getPointerSize();
-  auto JT = JTI->getJumpTables();
+  const auto &JT = JTI->getJumpTables();
 
   // Emit an additional section to store the correlation info as pairs of
   // addresses, each pair contains the address of a jump instruction (jr) and

>From 21ada655dbdd37b44eb62fff134be5fb97344b9d Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:34:48 +0000
Subject: [PATCH 5/9] [CommandLine] Avoid vector copy for const argument (NFC)

---
 llvm/lib/Support/CommandLine.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 5095b298fd42d..d7a28745a4669 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -2557,7 +2557,7 @@ class HelpPrinterWrapper {
 namespace {
 class VersionPrinter {
 public:
-  void print(std::vector<VersionPrinterTy> ExtraPrinters = {}) {
+  void print(const std::vector<VersionPrinterTy> &ExtraPrinters) {
     raw_ostream &OS = outs();
 #ifdef PACKAGE_VENDOR
     OS << PACKAGE_VENDOR << " ";

>From 00855524540f80e0c97c91edd6e779e8da9dbccf Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:37:18 +0000
Subject: [PATCH 6/9] [InstCombine] Replace vector copy with move semantic
 (NFC)

---
 llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 8c64105b63fe4..f2e827221e8cf 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -4831,7 +4831,7 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase 
&Call) {
       GCR.setOperand(2, ConstantInt::get(OpIntTy2, Val2Idx[DerivedPtr]));
     }
     // Create new statepoint instruction.
-    OperandBundleDef NewBundle("gc-live", NewLiveGc);
+    OperandBundleDef NewBundle("gc-live", std::move(NewLiveGc));
     return CallBase::Create(&Call, NewBundle);
   }
   default: { break; }

>From 12c1d6000ca6facf1d2aec4fdf0afa2ee0703582 Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:40:17 +0000
Subject: [PATCH 7/9] [AMDGPU] Replace copy with move semantics (NFC)

SplitProposal with vector field may be copid multiple times in
RecursiveSearchSplitting
---
 llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
index b7078825928be..581a3df70b994 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -991,7 +991,7 @@ void RecursiveSearchSplitting::run() {
   {
     SplitModuleTimer SMT("recursive_search_pick", "partitioning");
     SplitProposal SP(SG, NumParts);
-    pickPartition(/*BranchDepth=*/0, /*Idx=*/0, SP);
+    pickPartition(/*BranchDepth=*/0, /*Idx=*/0, std::move(SP));
   }
 }
 
@@ -1161,7 +1161,7 @@ void RecursiveSearchSplitting::pickPartition(unsigned 
Depth, unsigned Idx,
   SP.setName("recursive_search (depth=" + std::to_string(Depth) + ") #" +
              std::to_string(NumProposalsSubmitted++));
   LLVM_DEBUG(dbgs() << '\n');
-  SubmitProposal(SP);
+  SubmitProposal(std::move(SP));
 }
 
 std::pair<unsigned, CostType>

>From 699b110b477698a9af86edbe5065f81188314c57 Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:44:41 +0000
Subject: [PATCH 8/9] [-Wunsafe-buffer-usage] Replace vector copy with
 reference (NFC)

VariableGroupsManagerImpl copies a vector in ctor. At its single use
site in applyGadgets, the object VarGrpMgr always holds a valid to
`Groups`. Thus such replacement is safe from dangling reference.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index da19b9d3902f1..4c7ff12af8a0d 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -4241,7 +4241,7 @@ getNaiveStrategy(llvm::iterator_range<VarDeclIterTy> 
UnsafeVars) {
 
 //  Manages variable groups:
 class VariableGroupsManagerImpl : public VariableGroupsManager {
-  const std::vector<VarGrpTy> Groups;
+  const std::vector<VarGrpTy> &Groups;
   const std::map<const VarDecl *, unsigned> &VarGrpMap;
   const llvm::SetVector<const VarDecl *> &GrpsUnionForParms;
 

>From ece18dcd09d5431de763fd6106cf4c4988f498f1 Mon Sep 17 00:00:00 2001
From: sfu <[email protected]>
Date: Wed, 7 Jan 2026 03:51:28 +0000
Subject: [PATCH 9/9] [AMDGPU] replace copy with const reference (NFC)

V2SCopyInfo, containing a SetVector, gets copid in iteration. By
reordering the erase logic, such replacement is safe from dangling
reference.
---
 llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp 
b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
index 39a6a7762eea5..45891f5aa0c7a 100644
--- a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
@@ -1072,7 +1072,7 @@ void 
SIFixSGPRCopies::lowerVGPR2SGPRCopies(MachineFunction &MF) {
     unsigned CurID = LoweringWorklist.pop_back_val();
     auto *CurInfoIt = V2SCopies.find(CurID);
     if (CurInfoIt != V2SCopies.end()) {
-      V2SCopyInfo C = CurInfoIt->second;
+      const V2SCopyInfo &C = CurInfoIt->second;
       LLVM_DEBUG(dbgs() << "Processing ...\n"; C.dump());
       for (auto S : C.Siblings) {
         auto *SibInfoIt = V2SCopies.find(S);
@@ -1089,10 +1089,10 @@ void 
SIFixSGPRCopies::lowerVGPR2SGPRCopies(MachineFunction &MF) {
       }
       LLVM_DEBUG(dbgs() << "V2S copy " << *C.Copy
                         << " is being turned to VALU\n");
+      Copies.insert(C.Copy);
       // TODO: MapVector::erase is inefficient. Do bulk removal with remove_if
       // instead.
       V2SCopies.erase(C.ID);
-      Copies.insert(C.Copy);
     }
   }
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to