[llvm] f2e4ba0 - Avoid repeated checks and context lookup in llvm::Instruction::getAAMetadata
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 21 23:43:12 PDT 2022
Author: serge-sans-paille
Date: 2022-10-22T08:30:53+02:00
New Revision: f2e4ba0e3d40b9f3d5630dcda5e82b1a98f28410
URL: https://github.com/llvm/llvm-project/commit/f2e4ba0e3d40b9f3d5630dcda5e82b1a98f28410
DIFF: https://github.com/llvm/llvm-project/commit/f2e4ba0e3d40b9f3d5630dcda5e82b1a98f28410.diff
LOG: Avoid repeated checks and context lookup in llvm::Instruction::getAAMetadata
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
Differential Revision: https://reviews.llvm.org/D136503
Added:
Modified:
llvm/lib/IR/Metadata.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index fe7d9c1b20328..052f3b1b37ded 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -1461,10 +1461,15 @@ void Instruction::addAnnotationMetadata(StringRef Name) {
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 interested 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;
}
More information about the llvm-commits
mailing list