-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-ir Author: Florian Hahn (fhahn) ChangesAdd Instruction::PoisonGeneratingMetadataIDs containing IDs of poison-generating metadata to allow easier re-use. Currently it is a static const array in Instruction, maybe here's a better place? Full diff: https://github.com/llvm/llvm-project/pull/123188.diff 2 Files Affected:
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index aa480aa8d98636..645aa57d053e2e 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -503,6 +503,10 @@ class Instruction : public User,
/// Determine whether the the nneg flag is set.
bool hasNonNeg() const LLVM_READONLY;
+ /// Metadata IDs that may generate poison.
+ constexpr static const unsigned PoisonGeneratingMetadataIDs[] = {
+ LLVMContext::MD_range, LLVMContext::MD_nonnull, LLVMContext::MD_align};
+
/// Return true if this operator has flags which may cause this instruction
/// to evaluate to poison despite having non-poison inputs.
bool hasPoisonGeneratingFlags() const LLVM_READONLY;
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 147cd84125c8d1..12aefd8b1e96c1 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -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(PoisonGeneratingMetadataIDs,
+ [this](unsigned ID) { return hasMetadata(ID); });
}
bool Instruction::hasNonDebugLocLoopMetadata() const {
@@ -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 : PoisonGeneratingMetadataIDs)
+ eraseMetadata(ID);
}
bool Instruction::hasPoisonGeneratingReturnAttributes() const {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add Instruction::PoisonGeneratingMetadataIDs containing IDs of poison-generating metadata to allow easier re-use.
Currently it is a static const array in Instruction, maybe here's a better place?
Metadata::PoisonGeneratingIDs
maybe? No strong opinion.
a679a5b
to
51b24dc
Compare
Moved there, as it is overall a bit more compact when used outside Instruction:: :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also use this array in ArgumentPromotion:
llvm-project/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
Lines 256 to 264 in 8965dd4
// Only transfer poison-generating metadata if we also have | |
// !noundef. | |
// TODO: Without !noundef, we could merge this metadata across | |
// all promoted loads. | |
if (LI->hasMetadata(LLVMContext::MD_noundef)) | |
LI->copyMetadata(*Pair.second.MustExecInstr, | |
{LLVMContext::MD_range, LLVMContext::MD_nonnull, | |
LLVMContext::MD_align}); | |
} |
Add Instruction::PoisonGeneratingMetadataIDs containing IDs of poison-generating metadata to allow easier re-use. Currently it is a static const array in Instruction, maybe here's a better place?
51b24dc
to
e37db0a
Compare
Done, thanks! |
…123188) Add Metadata::PoisonGeneratingIDs containing IDs of poison-generating metadata to allow easier re-use. PR: llvm/llvm-project#123188
Add Metadata::PoisonGeneratingIDs containing IDs of poison-generating metadata to allow easier re-use.