[llvm] [GlobalMerge] Use vector::assign in place of fill+resize. NFC (PR #85723)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 18 17:46:45 PDT 2024


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/85723

Noticed while reviewing the code.

If the resize causes a new allocation, this will fill the new allocation with zeroes directly. Previously, we would fill the old allocation with zeroes, then copy them to the new allocation before filling the additional space with zeros.

>From 5eb6a3b041cf119986d49849a7595f9178754cbc Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 18 Mar 2024 17:42:30 -0700
Subject: [PATCH] [GlobalMerge] Use vector::assign in place of fill+resize. NFC

Noticed while reviewing the code.

If the resize causes a new allocation, this will fill the new
allocation with zeroes directly. Previously, we would fill the old
allocation with zeroes, then copy them to the new allocation before
filling the additional space with zeros.
---
 llvm/lib/CodeGen/GlobalMerge.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index 4941d5b01ae0f3..545ee1741834a1 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -309,10 +309,9 @@ bool GlobalMergeImpl::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
   for (size_t GI = 0, GE = Globals.size(); GI != GE; ++GI) {
     GlobalVariable *GV = Globals[GI];
 
-    // Reset the encountered sets for this global...
-    std::fill(EncounteredUGS.begin(), EncounteredUGS.end(), 0);
-    // ...and grow it in case we created new sets for the previous global.
-    EncounteredUGS.resize(UsedGlobalSets.size());
+    // Reset the encountered sets for this global and grow it in case we created
+    // new sets for the previous global.
+    EncounteredUGS.assign(UsedGlobalSets.size(), 0);
 
     // We might need to create a set that only consists of the current global.
     // Keep track of its index into UsedGlobalSets.



More information about the llvm-commits mailing list