[llvm] [JumpThreading][GVN] Copy metadata when inserting preload into preds (PR #134403)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 23 01:57:27 PDT 2025
================
@@ -1516,26 +1516,24 @@ void GVNPass::eliminatePartiallyRedundantLoad(
MSSAU->insertUse(cast<MemoryUse>(NewAccess), /*RenameUses=*/true);
}
- // Transfer the old load's AA tags to the new load.
- AAMDNodes Tags = Load->getAAMetadata();
- if (Tags)
- NewLoad->setAAMetadata(Tags);
-
- if (auto *MD = Load->getMetadata(LLVMContext::MD_invariant_load))
- NewLoad->setMetadata(LLVMContext::MD_invariant_load, MD);
- if (auto *InvGroupMD = Load->getMetadata(LLVMContext::MD_invariant_group))
- NewLoad->setMetadata(LLVMContext::MD_invariant_group, InvGroupMD);
- if (auto *RangeMD = Load->getMetadata(LLVMContext::MD_range))
- NewLoad->setMetadata(LLVMContext::MD_range, RangeMD);
- if (auto *AccessMD = Load->getMetadata(LLVMContext::MD_access_group))
- if (LI->getLoopFor(Load->getParent()) == LI->getLoopFor(UnavailableBlock))
- NewLoad->setMetadata(LLVMContext::MD_access_group, AccessMD);
-
- // We do not propagate the old load's debug location, because the new
- // load now lives in a different BB, and we want to avoid a jumpy line
- // table.
- // FIXME: How do we retain source locations without causing poor debugging
- // behavior?
+ NewLoad->copyMetadata(*Load);
+ std::optional<bool> TransfersExecution = std::nullopt;
+ NewLoad->eraseMetadataIf([&](unsigned Kind, const MDNode *MD) {
+ if (Kind == LLVMContext::MD_dbg || Kind == LLVMContext::MD_annotation)
+ return false;
+ if (is_contained(Metadata::PoisonGeneratingIDs, Kind))
+ return false;
+ // Try to salvage UB-implying metadata if we know it is guaranteed to
+ // transfer the execution to the original load.
+ if (!TransfersExecution.has_value()) {
+ // TEST ONLY
+ assert(
----------------
dtcxzyw wrote:
I am not sure if it holds for GVN.
https://github.com/llvm/llvm-project/pull/134403
More information about the llvm-commits
mailing list