-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[MIPatternMatch] Add m_GUMin and m_GUMax #121068
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
[MIPatternMatch] Add m_GUMin and m_GUMax #121068
Conversation
And make all unsigned and signed versions of min/max matchers commutative, since we already made a precedent of m_GAdd that is commutative by default.
|
@llvm/pr-subscribers-llvm-globalisel Author: Min-Yih Hsu (mshockwave) ChangesAnd make all unsigned and signed versions of min/max matchers commutative, since we already made a precedent of m_GAdd that is commutative by default. Full diff: https://github.com/llvm/llvm-project/pull/121068.diff 2 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
index ea6ed322e9b192..95d28834900e00 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
@@ -538,15 +538,27 @@ m_GAShr(const LHS &L, const RHS &R) {
}
template <typename LHS, typename RHS>
-inline BinaryOp_match<LHS, RHS, TargetOpcode::G_SMAX, false>
+inline BinaryOp_match<LHS, RHS, TargetOpcode::G_SMAX, true>
m_GSMax(const LHS &L, const RHS &R) {
- return BinaryOp_match<LHS, RHS, TargetOpcode::G_SMAX, false>(L, R);
+ return BinaryOp_match<LHS, RHS, TargetOpcode::G_SMAX, true>(L, R);
}
template <typename LHS, typename RHS>
-inline BinaryOp_match<LHS, RHS, TargetOpcode::G_SMIN, false>
+inline BinaryOp_match<LHS, RHS, TargetOpcode::G_SMIN, true>
m_GSMin(const LHS &L, const RHS &R) {
- return BinaryOp_match<LHS, RHS, TargetOpcode::G_SMIN, false>(L, R);
+ return BinaryOp_match<LHS, RHS, TargetOpcode::G_SMIN, true>(L, R);
+}
+
+template <typename LHS, typename RHS>
+inline BinaryOp_match<LHS, RHS, TargetOpcode::G_UMAX, true>
+m_GUMax(const LHS &L, const RHS &R) {
+ return BinaryOp_match<LHS, RHS, TargetOpcode::G_UMAX, true>(L, R);
+}
+
+template <typename LHS, typename RHS>
+inline BinaryOp_match<LHS, RHS, TargetOpcode::G_UMIN, true>
+m_GUMin(const LHS &L, const RHS &R) {
+ return BinaryOp_match<LHS, RHS, TargetOpcode::G_UMIN, true>(L, R);
}
// Helper for unary instructions (G_[ZSA]EXT/G_TRUNC) etc
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
index 59a86fa5646f36..2088a3f81ed57a 100644
--- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -224,6 +224,32 @@ TEST_F(AArch64GISelMITest, MatchBinaryOp) {
auto MIBAddCst = B.buildAdd(s64, MIBCst, Copies[0]);
auto MIBUnmerge = B.buildUnmerge({s32, s32}, B.buildConstant(s64, 42));
+ // Match min/max, and make sure they're commutative.
+ auto SMin = B.buildSMin(s64, Copies[2], MIBAdd);
+ EXPECT_TRUE(mi_match(SMin.getReg(0), *MRI,
+ m_GSMin(m_GAdd(m_Reg(Src1), m_Reg(Src2)), m_Reg(Src0))));
+ EXPECT_EQ(Src0, Copies[2]);
+ EXPECT_EQ(Src1, Copies[0]);
+ EXPECT_EQ(Src2, Copies[1]);
+ auto SMax = B.buildSMax(s64, Copies[2], MIBAdd);
+ EXPECT_TRUE(mi_match(SMax.getReg(0), *MRI,
+ m_GSMax(m_GAdd(m_Reg(Src1), m_Reg(Src2)), m_Reg(Src0))));
+ EXPECT_EQ(Src0, Copies[2]);
+ EXPECT_EQ(Src1, Copies[0]);
+ EXPECT_EQ(Src2, Copies[1]);
+ auto UMin = B.buildUMin(s64, Copies[2], MIBAdd);
+ EXPECT_TRUE(mi_match(UMin.getReg(0), *MRI,
+ m_GUMin(m_GAdd(m_Reg(Src1), m_Reg(Src2)), m_Reg(Src0))));
+ EXPECT_EQ(Src0, Copies[2]);
+ EXPECT_EQ(Src1, Copies[0]);
+ EXPECT_EQ(Src2, Copies[1]);
+ auto UMax = B.buildUMax(s64, Copies[2], MIBAdd);
+ EXPECT_TRUE(mi_match(UMax.getReg(0), *MRI,
+ m_GUMax(m_GAdd(m_Reg(Src1), m_Reg(Src2)), m_Reg(Src0))));
+ EXPECT_EQ(Src0, Copies[2]);
+ EXPECT_EQ(Src1, Copies[0]);
+ EXPECT_EQ(Src2, Copies[1]);
+
// m_BinOp with opcode.
// Match binary instruction, opcode and its non-commutative operands.
match = mi_match(MIBAddCst, *MRI,
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/197/builds/52 Here is the relevant piece of the build log for the reference |
And make all unsigned and signed versions of min/max matchers commutative, since we already made a precedent of m_GAdd that is commutative by default.