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

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 18 21:14:30 PDT 2024


Author: Craig Topper
Date: 2024-03-18T21:14:26-07:00
New Revision: e04dd68a3a26d3ebdc2db07cf2f8807a02d30ce2

URL: https://github.com/llvm/llvm-project/commit/e04dd68a3a26d3ebdc2db07cf2f8807a02d30ce2
DIFF: https://github.com/llvm/llvm-project/commit/e04dd68a3a26d3ebdc2db07cf2f8807a02d30ce2.diff

LOG: [GlobalMerge] Use vector::assign in place of fill+resize. NFC (#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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/GlobalMerge.cpp

Removed: 
    


################################################################################
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