Skip to content

[IR] Provide array with poison-generating metadata IDs. #123188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/IR/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class Metadata {
void printAsOperand(raw_ostream &OS, ModuleSlotTracker &MST,
const Module *M = nullptr) const;
/// @}

/// Metadata IDs that may generate poison.
constexpr static const unsigned PoisonGeneratingIDs[] = {
LLVMContext::MD_range, LLVMContext::MD_nonnull, LLVMContext::MD_align};
};

// Create wrappers for C Binding types (see CBindingWrapping.h).
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,8 @@ void Instruction::dropPoisonGeneratingFlags() {
}

bool Instruction::hasPoisonGeneratingMetadata() const {
return hasMetadata(LLVMContext::MD_range) ||
hasMetadata(LLVMContext::MD_nonnull) ||
hasMetadata(LLVMContext::MD_align);
return any_of(Metadata::PoisonGeneratingIDs,
[this](unsigned ID) { return hasMetadata(ID); });
}

bool Instruction::hasNonDebugLocLoopMetadata() const {
Expand All @@ -487,9 +486,8 @@ bool Instruction::hasNonDebugLocLoopMetadata() const {
}

void Instruction::dropPoisonGeneratingMetadata() {
eraseMetadata(LLVMContext::MD_range);
eraseMetadata(LLVMContext::MD_nonnull);
eraseMetadata(LLVMContext::MD_align);
for (unsigned ID : Metadata::PoisonGeneratingIDs)
eraseMetadata(ID);
}

bool Instruction::hasPoisonGeneratingReturnAttributes() const {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
// all promoted loads.
if (LI->hasMetadata(LLVMContext::MD_noundef))
LI->copyMetadata(*Pair.second.MustExecInstr,
{LLVMContext::MD_range, LLVMContext::MD_nonnull,
LLVMContext::MD_align});
Metadata::PoisonGeneratingIDs);
}
Args.push_back(LI);
ArgAttrVec.push_back(AttributeSet());
Expand Down
Loading