@@ -3308,13 +3308,11 @@ bool llvm::removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU,
33083308 return Changed;
33093309}
33103310
3311- // FIXME: https://github.com/llvm/llvm-project/issues/121495
3312- // Once external callers of this function are removed, either inline into
3313- // combineMetadataForCSE, or internalize and remove KnownIDs parameter.
3314- void llvm::combineMetadata (Instruction *K, const Instruction *J,
3315- ArrayRef<unsigned > KnownIDs, bool DoesKMove) {
3311+ // / If AAOnly is set, only intersect alias analysis metadata and preserve other
3312+ // / known metadata. Unknown metadata is always dropped.
3313+ static void combineMetadata (Instruction *K, const Instruction *J,
3314+ bool DoesKMove, bool AAOnly = false ) {
33163315 SmallVector<std::pair<unsigned , MDNode *>, 4 > Metadata;
3317- K->dropUnknownNonDebugMetadata (KnownIDs);
33183316 K->getAllMetadataOtherThanDebugLoc (Metadata);
33193317 for (const auto &MD : Metadata) {
33203318 unsigned Kind = MD.first ;
@@ -3323,16 +3321,13 @@ void llvm::combineMetadata(Instruction *K, const Instruction *J,
33233321
33243322 switch (Kind) {
33253323 default :
3326- // FIXME: https://github.com/llvm/llvm-project/issues/121495
3327- // Change to removing only explicitly listed other metadata, and assert
3328- // on unknown metadata, to avoid inadvertently dropping newly added
3329- // metadata types.
33303324 K->setMetadata (Kind, nullptr ); // Remove unknown metadata
33313325 break ;
33323326 case LLVMContext::MD_dbg:
33333327 llvm_unreachable (" getAllMetadataOtherThanDebugLoc returned a MD_dbg" );
33343328 case LLVMContext::MD_DIAssignID:
3335- K->mergeDIAssignID (J);
3329+ if (!AAOnly)
3330+ K->mergeDIAssignID (J);
33363331 break ;
33373332 case LLVMContext::MD_tbaa:
33383333 if (DoesKMove)
@@ -3353,11 +3348,12 @@ void llvm::combineMetadata(Instruction *K, const Instruction *J,
33533348 intersectAccessGroups (K, J));
33543349 break ;
33553350 case LLVMContext::MD_range:
3356- if (DoesKMove || !K->hasMetadata (LLVMContext::MD_noundef))
3351+ if (!AAOnly && ( DoesKMove || !K->hasMetadata (LLVMContext::MD_noundef) ))
33573352 K->setMetadata (Kind, MDNode::getMostGenericRange (JMD, KMD));
33583353 break ;
33593354 case LLVMContext::MD_fpmath:
3360- K->setMetadata (Kind, MDNode::getMostGenericFPMath (JMD, KMD));
3355+ if (!AAOnly)
3356+ K->setMetadata (Kind, MDNode::getMostGenericFPMath (JMD, KMD));
33613357 break ;
33623358 case LLVMContext::MD_invariant_load:
33633359 // If K moves, only set the !invariant.load if it is present in both
@@ -3366,7 +3362,7 @@ void llvm::combineMetadata(Instruction *K, const Instruction *J,
33663362 K->setMetadata (Kind, JMD);
33673363 break ;
33683364 case LLVMContext::MD_nonnull:
3369- if (DoesKMove || !K->hasMetadata (LLVMContext::MD_noundef))
3365+ if (!AAOnly && ( DoesKMove || !K->hasMetadata (LLVMContext::MD_noundef) ))
33703366 K->setMetadata (Kind, JMD);
33713367 break ;
33723368 case LLVMContext::MD_invariant_group:
@@ -3376,36 +3372,39 @@ void llvm::combineMetadata(Instruction *K, const Instruction *J,
33763372 // Combine MMRAs
33773373 break ;
33783374 case LLVMContext::MD_align:
3379- if (DoesKMove || !K->hasMetadata (LLVMContext::MD_noundef))
3375+ if (!AAOnly && ( DoesKMove || !K->hasMetadata (LLVMContext::MD_noundef) ))
33803376 K->setMetadata (
33813377 Kind, MDNode::getMostGenericAlignmentOrDereferenceable (JMD, KMD));
33823378 break ;
33833379 case LLVMContext::MD_dereferenceable:
33843380 case LLVMContext::MD_dereferenceable_or_null:
3385- if (DoesKMove)
3381+ if (!AAOnly && DoesKMove)
33863382 K->setMetadata (Kind,
33873383 MDNode::getMostGenericAlignmentOrDereferenceable (JMD, KMD));
33883384 break ;
33893385 case LLVMContext::MD_memprof:
3390- K->setMetadata (Kind, MDNode::getMergedMemProfMetadata (KMD, JMD));
3386+ if (!AAOnly)
3387+ K->setMetadata (Kind, MDNode::getMergedMemProfMetadata (KMD, JMD));
33913388 break ;
33923389 case LLVMContext::MD_callsite:
3393- K->setMetadata (Kind, MDNode::getMergedCallsiteMetadata (KMD, JMD));
3390+ if (!AAOnly)
3391+ K->setMetadata (Kind, MDNode::getMergedCallsiteMetadata (KMD, JMD));
33943392 break ;
33953393 case LLVMContext::MD_preserve_access_index:
33963394 // Preserve !preserve.access.index in K.
33973395 break ;
33983396 case LLVMContext::MD_noundef:
33993397 // If K does move, keep noundef if it is present in both instructions.
3400- if (DoesKMove)
3398+ if (!AAOnly && DoesKMove)
34013399 K->setMetadata (Kind, JMD);
34023400 break ;
34033401 case LLVMContext::MD_nontemporal:
34043402 // Preserve !nontemporal if it is present on both instructions.
3405- K->setMetadata (Kind, JMD);
3403+ if (!AAOnly)
3404+ K->setMetadata (Kind, JMD);
34063405 break ;
34073406 case LLVMContext::MD_prof:
3408- if (DoesKMove)
3407+ if (!AAOnly && DoesKMove)
34093408 K->setMetadata (Kind, MDNode::getMergedProfMetadata (KMD, JMD, K, J));
34103409 break ;
34113410 case LLVMContext::MD_noalias_addrspace:
@@ -3437,28 +3436,12 @@ void llvm::combineMetadata(Instruction *K, const Instruction *J,
34373436}
34383437
34393438void llvm::combineMetadataForCSE (Instruction *K, const Instruction *J,
3440- bool KDominatesJ) {
3441- unsigned KnownIDs[] = {LLVMContext::MD_tbaa,
3442- LLVMContext::MD_alias_scope,
3443- LLVMContext::MD_noalias,
3444- LLVMContext::MD_range,
3445- LLVMContext::MD_fpmath,
3446- LLVMContext::MD_invariant_load,
3447- LLVMContext::MD_nonnull,
3448- LLVMContext::MD_invariant_group,
3449- LLVMContext::MD_align,
3450- LLVMContext::MD_dereferenceable,
3451- LLVMContext::MD_dereferenceable_or_null,
3452- LLVMContext::MD_access_group,
3453- LLVMContext::MD_preserve_access_index,
3454- LLVMContext::MD_prof,
3455- LLVMContext::MD_nontemporal,
3456- LLVMContext::MD_noundef,
3457- LLVMContext::MD_mmra,
3458- LLVMContext::MD_noalias_addrspace,
3459- LLVMContext::MD_memprof,
3460- LLVMContext::MD_callsite};
3461- combineMetadata (K, J, KnownIDs, KDominatesJ);
3439+ bool DoesKMove) {
3440+ combineMetadata (K, J, DoesKMove);
3441+ }
3442+
3443+ void llvm::combineAAMetadata (Instruction *K, const Instruction *J) {
3444+ combineMetadata (K, J, /* DoesKMove=*/ true , /* AAOnly=*/ true );
34623445}
34633446
34643447void llvm::copyMetadataForLoad (LoadInst &Dest, const LoadInst &Source) {
0 commit comments