Skip to content

[InlineCost] Use a const reference (NFC) #95687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

The use of a const reference here saves 0.18% of heap allocations
during the compilation of a large preprocessed file, namely
X86ISelLowering.cpp, for the X86 target.

Note that GetTLI returns a const reference, so we don't have to worry
about a dangling reference.

The use of a const reference here saves 0.18% of heap allocations
during the compilation of a large preprocessed file, namely
X86ISelLowering.cpp, for the X86 target.

Note that GetTLI returns a const reference, so we don't have to worry
about a dangling reference.
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Jun 16, 2024
@kazutakahirata kazutakahirata requested review from nikic and MaskRay June 16, 2024 03:19
@llvmbot
Copy link
Member

llvmbot commented Jun 16, 2024

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

Changes

The use of a const reference here saves 0.18% of heap allocations
during the compilation of a large preprocessed file, namely
X86ISelLowering.cpp, for the X86 target.

Note that GetTLI returns a const reference, so we don't have to worry
about a dangling reference.


Full diff: https://github.com/llvm/llvm-project/pull/95687.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/InlineCost.cpp (+1-1)
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index f5b17dca49735..c3aeac7492804 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -2887,7 +2887,7 @@ static bool functionsHaveCompatibleAttributes(
   // caches the most recently created TLI in the TargetLibraryInfoWrapperPass
   // object, and always returns the same object (which is overwritten on each
   // GetTLI call). Therefore we copy the first result.
-  auto CalleeTLI = GetTLI(*Callee);
+  const auto &CalleeTLI = GetTLI(*Callee);
   return (IgnoreTTIInlineCompatible ||
           TTI.areInlineCompatible(Caller, Callee)) &&
          GetTLI(*Caller).areInlineCompatible(CalleeTLI,

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment directly above. The copy here is needed for the legacy pass manager. It looks like we still support AlwaysInliner for the legacy PM.

@kazutakahirata
Copy link
Contributor Author

See the comment directly above. The copy here is needed for the legacy pass manager. It looks like we still support AlwaysInliner for the legacy PM.

Ah, thank you for pointing this out!

@kazutakahirata kazutakahirata deleted the cleanup_memory_alloc_18bp_functionsHaveCompatibleAttributes branch June 16, 2024 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants