diff options
author | Snehasish Kumar <snehasishk@google.com> | 2025-04-02 11:13:45 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-02 11:13:45 -0600 |
commit | c18994c7cdf68dfbb35c998909aa837169bb0c25 (patch) | |
tree | 17efad8acb2d1c0554d41635426b5d6d34b9946c /llvm/lib/Transforms/Utils/Local.cpp | |
parent | dde0be9d9709f7c983443327024fc5983a9b18d1 (diff) | |
download | llvm-c18994c7cdf68dfbb35c998909aa837169bb0c25.zip llvm-c18994c7cdf68dfbb35c998909aa837169bb0c25.tar.gz llvm-c18994c7cdf68dfbb35c998909aa837169bb0c25.tar.bz2 |
[Metadata] Preserve MD_prof when merging instructions when one is missing. (#132433)
Preserve branch weight metadata when merging instructions if one of the
instructions is missing metadata. This is similar in behaviour to what
we do today for other types of metadata such as mmra, memprof and
callsite metadata.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index edec0e7..c136825 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -3355,9 +3355,10 @@ static void combineMetadata(Instruction *K, const Instruction *J, case LLVMContext::MD_invariant_group: // Preserve !invariant.group in K. break; - // Keep empty cases for mmra, memprof, and callsite to prevent them from - // being removed as unknown metadata. The actual merging is handled + // Keep empty cases for prof, mmra, memprof, and callsite to prevent them + // from being removed as unknown metadata. The actual merging is handled // separately below. + case LLVMContext::MD_prof: case LLVMContext::MD_mmra: case LLVMContext::MD_memprof: case LLVMContext::MD_callsite: @@ -3386,10 +3387,6 @@ static void combineMetadata(Instruction *K, const Instruction *J, if (!AAOnly) K->setMetadata(Kind, JMD); break; - case LLVMContext::MD_prof: - if (!AAOnly && DoesKMove) - K->setMetadata(Kind, MDNode::getMergedProfMetadata(KMD, JMD, K, J)); - break; case LLVMContext::MD_noalias_addrspace: if (DoesKMove) K->setMetadata(Kind, @@ -3436,6 +3433,16 @@ static void combineMetadata(Instruction *K, const Instruction *J, K->setMetadata(LLVMContext::MD_callsite, MDNode::getMergedCallsiteMetadata(KCallSite, JCallSite)); } + + // Merge prof metadata. + // Handle separately to support cases where only one instruction has the + // metadata. + auto *JProf = J->getMetadata(LLVMContext::MD_prof); + auto *KProf = K->getMetadata(LLVMContext::MD_prof); + if (!AAOnly && (JProf || KProf)) { + K->setMetadata(LLVMContext::MD_prof, + MDNode::getMergedProfMetadata(KProf, JProf, K, J)); + } } void llvm::combineMetadataForCSE(Instruction *K, const Instruction *J, |