diff options
author | Snehasish Kumar <snehasishk@google.com> | 2025-04-02 11:10:02 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-02 11:10:02 -0600 |
commit | dde0be9d9709f7c983443327024fc5983a9b18d1 (patch) | |
tree | b17d29a0b284a3b1f14f288805fb45d112cdf4c6 /llvm/lib/Transforms/Utils/Local.cpp | |
parent | d7724c8ea313e5d64ef35102958213dcd98f53ea (diff) | |
download | llvm-dde0be9d9709f7c983443327024fc5983a9b18d1.zip llvm-dde0be9d9709f7c983443327024fc5983a9b18d1.tar.gz llvm-dde0be9d9709f7c983443327024fc5983a9b18d1.tar.bz2 |
[Metadata] Handle memprof, callsite merging when one is missing. (#132106)
For memprof and callsite metadata we want to pick one deterministically
and keep that even if one of them may be missing.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 95f0d09..edec0e7 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -3355,8 +3355,12 @@ 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 + // separately below. case LLVMContext::MD_mmra: - // Combine MMRAs + case LLVMContext::MD_memprof: + case LLVMContext::MD_callsite: break; case LLVMContext::MD_align: if (!AAOnly && (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef))) @@ -3369,14 +3373,6 @@ static void combineMetadata(Instruction *K, const Instruction *J, K->setMetadata(Kind, MDNode::getMostGenericAlignmentOrDereferenceable(JMD, KMD)); break; - case LLVMContext::MD_memprof: - if (!AAOnly) - K->setMetadata(Kind, MDNode::getMergedMemProfMetadata(KMD, JMD)); - break; - case LLVMContext::MD_callsite: - if (!AAOnly) - K->setMetadata(Kind, MDNode::getMergedCallsiteMetadata(KMD, JMD)); - break; case LLVMContext::MD_preserve_access_index: // Preserve !preserve.access.index in K. break; @@ -3420,6 +3416,26 @@ static void combineMetadata(Instruction *K, const Instruction *J, K->setMetadata(LLVMContext::MD_mmra, MMRAMetadata::combine(K->getContext(), JMMRA, KMMRA)); } + + // Merge memprof metadata. + // Handle separately to support cases where only one instruction has the + // metadata. + auto *JMemProf = J->getMetadata(LLVMContext::MD_memprof); + auto *KMemProf = K->getMetadata(LLVMContext::MD_memprof); + if (!AAOnly && (JMemProf || KMemProf)) { + K->setMetadata(LLVMContext::MD_memprof, + MDNode::getMergedMemProfMetadata(KMemProf, JMemProf)); + } + + // Merge callsite metadata. + // Handle separately to support cases where only one instruction has the + // metadata. + auto *JCallSite = J->getMetadata(LLVMContext::MD_callsite); + auto *KCallSite = K->getMetadata(LLVMContext::MD_callsite); + if (!AAOnly && (JCallSite || KCallSite)) { + K->setMetadata(LLVMContext::MD_callsite, + MDNode::getMergedCallsiteMetadata(KCallSite, JCallSite)); + } } void llvm::combineMetadataForCSE(Instruction *K, const Instruction *J, |