[PATCH] D107538: [GCov] Emit memset instead of stores in __llvm_gcov_reset

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 4 22:47:27 PDT 2021


aeubanks created this revision.
Herald added subscribers: asbirlea, george.burgess.iv, hiraditya.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

For a very large module, __llvm_gcov_reset can become very large.
__llvm_gcov_reset previously emitted stores to a bunch of globals in one
huge basic block. MemCpyOpt would turn many of these stores into
memsets, and updating MemorySSA would be extremely slow.

Verified that this makes the compile time of certain files go down
drastically (20min -> 5min).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107538

Files:
  llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
  llvm/test/Transforms/GCOVProfiling/module-flags.ll


Index: llvm/test/Transforms/GCOVProfiling/module-flags.ll
===================================================================
--- llvm/test/Transforms/GCOVProfiling/module-flags.ll
+++ llvm/test/Transforms/GCOVProfiling/module-flags.ll
@@ -30,5 +30,7 @@
 ;; Infer uwtable and "frame-pointer" from the module flags.
 ; CHECK: define internal void @__llvm_gcov_writeout() unnamed_addr #[[#ATTR:]]
 ; CHECK: define internal void @__llvm_gcov_reset() unnamed_addr #[[#ATTR]]
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast ([1 x i64]* @__llvm_gcov_ctr to i8*), i8 0, i64 0, i1 false)
 ; CHECK: define internal void @__llvm_gcov_init() unnamed_addr #[[#ATTR]]
 ; CHECK: attributes #[[#ATTR]] = { noinline nounwind uwtable "frame-pointer"="all" }
Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -1373,12 +1373,16 @@
 
   BasicBlock *Entry = BasicBlock::Create(*Ctx, "entry", ResetF);
   IRBuilder<> Builder(Entry);
+  LLVMContext &C = Entry->getContext();
 
   // Zero out the counters.
   for (const auto &I : CountersBySP) {
     GlobalVariable *GV = I.first;
-    Constant *Null = Constant::getNullValue(GV->getValueType());
-    Builder.CreateStore(Null, GV);
+    auto *GVTy = cast<ArrayType>(GV->getValueType());
+    Builder.CreateMemSet(GV, Constant::getNullValue(Type::getInt8Ty(C)),
+                         GVTy->getNumElements() *
+                             GVTy->getPrimitiveSizeInBits(),
+                         GV->getAlign());
   }
 
   Type *RetTy = ResetF->getReturnType();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107538.364353.patch
Type: text/x-patch
Size: 1725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210805/c9bcb929/attachment-0001.bin>


More information about the llvm-commits mailing list