Skip to content

Commit

Permalink
[InstCombine] Use combineMetadataForCSE in phi of loads fold
Browse files Browse the repository at this point in the history
Use combineMetadataForCSE instead of manually enumerating known
metadata kinds. This is a typical sinking transform for which
combineMetadataForCSE is safe to use (with DoesKMove=true).

Part of llvm#121495.
  • Loading branch information
nikic authored and shenhanc78 committed Jan 8, 2025
1 parent 5f1bd29 commit 7096266
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,33 +765,14 @@ Instruction *InstCombinerImpl::foldPHIArgLoadIntoPHI(PHINode &PN) {
NewPN->addIncoming(InVal, PN.getIncomingBlock(0));
LoadInst *NewLI =
new LoadInst(FirstLI->getType(), NewPN, "", IsVolatile, LoadAlignment);

unsigned KnownIDs[] = {
LLVMContext::MD_tbaa,
LLVMContext::MD_range,
LLVMContext::MD_invariant_load,
LLVMContext::MD_alias_scope,
LLVMContext::MD_noalias,
LLVMContext::MD_nonnull,
LLVMContext::MD_align,
LLVMContext::MD_dereferenceable,
LLVMContext::MD_dereferenceable_or_null,
LLVMContext::MD_access_group,
LLVMContext::MD_noundef,
};

for (unsigned ID : KnownIDs)
NewLI->setMetadata(ID, FirstLI->getMetadata(ID));
NewLI->copyMetadata(*FirstLI);

// Add all operands to the new PHI and combine TBAA metadata.
for (auto Incoming : drop_begin(zip(PN.blocks(), PN.incoming_values()))) {
BasicBlock *BB = std::get<0>(Incoming);
Value *V = std::get<1>(Incoming);
LoadInst *LI = cast<LoadInst>(V);
// FIXME: https://github.com/llvm/llvm-project/issues/121495
// Call combineMetadataForCSE instead, so that an explicit set of KnownIDs
// doesn't need to be maintained here.
combineMetadata(NewLI, LI, KnownIDs, true);
combineMetadataForCSE(NewLI, LI, true);
Value *NewInVal = LI->getOperand(0);
if (NewInVal != InVal)
InVal = nullptr;
Expand Down

0 comments on commit 7096266

Please sign in to comment.