-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Recommit "[PatternMatch] Fix issue of stale reference in new m_{I,F,}Cmp
matchers" (3rd Try)
#99292
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…}Cmp` matchers" (3rd Try) The first fix forgot to fixup the commutative matchers...
@llvm/pr-subscribers-llvm-ir Author: None (goldsteinn) ChangesThe first fix forgot to fixup the commutative matchers... Full diff: https://github.com/llvm/llvm-project/pull/99292.diff 2 Files Affected:
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 8ae47fb556b25..d9e27e087e705 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -1550,23 +1550,27 @@ template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy,
bool Commutable = false>
struct CmpClass_match {
- PredicateTy &Predicate;
+ PredicateTy *Predicate;
LHS_t L;
RHS_t R;
// The evaluation order is always stable, regardless of Commutability.
// The LHS is always matched first.
CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
- : Predicate(Pred), L(LHS), R(RHS) {}
+ : Predicate(&Pred), L(LHS), R(RHS) {}
+ CmpClass_match(const LHS_t &LHS, const RHS_t &RHS)
+ : Predicate(nullptr), L(LHS), R(RHS) {}
template <typename OpTy> bool match(OpTy *V) {
if (auto *I = dyn_cast<Class>(V)) {
if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
- Predicate = I->getPredicate();
+ if (Predicate)
+ *Predicate = I->getPredicate();
return true;
} else if (Commutable && L.match(I->getOperand(1)) &&
R.match(I->getOperand(0))) {
- Predicate = I->getSwappedPredicate();
+ if (Predicate)
+ *Predicate = I->getSwappedPredicate();
return true;
}
}
@@ -1595,22 +1599,19 @@ m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
template <typename LHS, typename RHS>
inline CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>
m_Cmp(const LHS &L, const RHS &R) {
- CmpInst::Predicate Unused;
- return CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>(Unused, L, R);
+ return CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>(L, R);
}
template <typename LHS, typename RHS>
inline CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>
m_ICmp(const LHS &L, const RHS &R) {
- ICmpInst::Predicate Unused;
- return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>(Unused, L, R);
+ return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>(L, R);
}
template <typename LHS, typename RHS>
inline CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>
m_FCmp(const LHS &L, const RHS &R) {
- FCmpInst::Predicate Unused;
- return CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>(Unused, L, R);
+ return CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>(L, R);
}
// Same as CmpClass, but instead of saving Pred as out output variable, match a
@@ -2681,9 +2682,7 @@ m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
template <typename LHS, typename RHS>
inline CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true>
m_c_ICmp(const LHS &L, const RHS &R) {
- ICmpInst::Predicate Unused;
- return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true>(Unused,
- L, R);
+ return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true>(L, R);
}
/// Matches a specific opcode with LHS and RHS in either order.
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index b82711ec244a6..309fcc93996bc 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -2235,7 +2235,7 @@ typedef ::testing::Types<std::tuple<Value*, Instruction*>,
MutableConstTestTypes;
TYPED_TEST_SUITE(MutableConstTest, MutableConstTestTypes, );
-TYPED_TEST(MutableConstTest, /* FIXME: UAR bug */ DISABLED_ICmp) {
+TYPED_TEST(MutableConstTest, ICmp) {
auto &IRB = PatternMatchTest::IRB;
typedef std::tuple_element_t<0, TypeParam> ValueType;
@@ -2319,7 +2319,7 @@ TYPED_TEST(MutableConstTest, /* FIXME: UAR bug */ DISABLED_ICmp) {
.match((InstructionType)IRB.CreateICmp(Pred, L, R)));
}
-TYPED_TEST(MutableConstTest, /* FIXME: UAR bug */ DISABLED_FCmp) {
+TYPED_TEST(MutableConstTest, FCmp) {
auto &IRB = PatternMatchTest::IRB;
typedef std::tuple_element_t<0, TypeParam> ValueType;
|
I reproduced the issue locally w/ asan and tested this fix accordingly. |
dtcxzyw
approved these changes
Jul 17, 2024
nikic
approved these changes
Jul 17, 2024
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
vitalybuka
approved these changes
Jul 17, 2024
yuxuanchen1997
pushed a commit
that referenced
this pull request
Jul 25, 2024
…}Cmp` matchers" (3rd Try) (#99292) The first fix forgot to fixup the commutative matchers...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first fix forgot to fixup the commutative matchers...