[PATCH] D136503: Avoid repeated checks and context lookup in llvm::Instruction::getAAMetadata

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 14:36:33 PDT 2022


serge-sans-paille created this revision.
serge-sans-paille added a reviewer: nikic.
Herald added a subscriber: hiraditya.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repeated call to Instruction::hasMetadata() and lookup in
getContext().pImpl->ValueMetadata are not needed when we always work on
the same instruction, avoid them.

This simple change leads to interesting and consistent speedups in
compile time, around -0.5% according to http://llvm-compile-time-tracker.com, see

  http://llvm-compile-time-tracker.com/compare.php?from=9708d88017d0c9adaea65a4f5a5b589b67f292e2&to=88482b9addd5917e9c5226847efeb5451c5f78c0&stat=instructions

for the performance impact.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136503

Files:
  llvm/lib/IR/Metadata.cpp


Index: llvm/lib/IR/Metadata.cpp
===================================================================
--- llvm/lib/IR/Metadata.cpp
+++ llvm/lib/IR/Metadata.cpp
@@ -1461,10 +1461,15 @@
 
 AAMDNodes Instruction::getAAMetadata() const {
   AAMDNodes Result;
-  Result.TBAA = getMetadata(LLVMContext::MD_tbaa);
-  Result.TBAAStruct = getMetadata(LLVMContext::MD_tbaa_struct);
-  Result.Scope = getMetadata(LLVMContext::MD_alias_scope);
-  Result.NoAlias = getMetadata(LLVMContext::MD_noalias);
+  // Not using Instruction::hasMetadata() because we're not interesting in
+  // DebugInfoMetadata
+  if (Value::hasMetadata()) {
+    const auto &Info = getContext().pImpl->ValueMetadata[this];
+    Result.TBAA = Info.lookup(LLVMContext::MD_tbaa);
+    Result.TBAAStruct = Info.lookup(LLVMContext::MD_tbaa_struct);
+    Result.Scope = Info.lookup(LLVMContext::MD_alias_scope);
+    Result.NoAlias = Info.lookup(LLVMContext::MD_noalias);
+  }
   return Result;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136503.469766.patch
Type: text/x-patch
Size: 955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221021/987decc3/attachment.bin>


More information about the llvm-commits mailing list