This is an archive of the discontinued LLVM Phabricator instance.

Avoid repeated checks and context lookup in llvm::Instruction::getAAMetadata
ClosedPublic

Authored by serge-sans-paille on Oct 21 2022, 2:36 PM.

Details

Summary

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.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2022, 2:36 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
serge-sans-paille requested review of this revision.Oct 21 2022, 2:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2022, 2:36 PM
nikic accepted this revision.Oct 21 2022, 2:46 PM

LGTM

I think given that this lives in Metadata.cpp, the direct access the metadata internals is fine. If there are performance-critical external users of this kind, we could add an API that accepts multiple MDKinds and returns results for all of them.

llvm/lib/IR/Metadata.cpp
1464–1472

interesting -> interested

This revision is now accepted and ready to land.Oct 21 2022, 2:46 PM
This revision was landed with ongoing or failed builds.Oct 21 2022, 11:43 PM
This revision was automatically updated to reflect the committed changes.