Skip to content

Commit bfa711a

Browse files
committed
[InstCombine] Use combineMetadataForCSE in phi of loads fold
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 #121495.
1 parent 20d7fa1 commit bfa711a

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -765,33 +765,14 @@ Instruction *InstCombinerImpl::foldPHIArgLoadIntoPHI(PHINode &PN) {
765765
NewPN->addIncoming(InVal, PN.getIncomingBlock(0));
766766
LoadInst *NewLI =
767767
new LoadInst(FirstLI->getType(), NewPN, "", IsVolatile, LoadAlignment);
768-
769-
unsigned KnownIDs[] = {
770-
LLVMContext::MD_tbaa,
771-
LLVMContext::MD_range,
772-
LLVMContext::MD_invariant_load,
773-
LLVMContext::MD_alias_scope,
774-
LLVMContext::MD_noalias,
775-
LLVMContext::MD_nonnull,
776-
LLVMContext::MD_align,
777-
LLVMContext::MD_dereferenceable,
778-
LLVMContext::MD_dereferenceable_or_null,
779-
LLVMContext::MD_access_group,
780-
LLVMContext::MD_noundef,
781-
};
782-
783-
for (unsigned ID : KnownIDs)
784-
NewLI->setMetadata(ID, FirstLI->getMetadata(ID));
768+
NewLI->copyMetadata(*FirstLI);
785769

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

0 commit comments

Comments
 (0)