summaryrefslogtreecommitdiff
path: root/unittests/IR/PatternMatch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/IR/PatternMatch.cpp')
-rw-r--r--unittests/IR/PatternMatch.cpp77
1 files changed, 61 insertions, 16 deletions
diff --git a/unittests/IR/PatternMatch.cpp b/unittests/IR/PatternMatch.cpp
index 02ef87f5b13e2..5c13ba6ecd90a 100644
--- a/unittests/IR/PatternMatch.cpp
+++ b/unittests/IR/PatternMatch.cpp
@@ -91,15 +91,26 @@ TEST_F(PatternMatchTest, FloatingPointOrderedMin) {
EXPECT_FALSE(m_OrdFMin(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpOGT(L, R), L, R)));
- // Test match on OGE with inverted select.
- EXPECT_TRUE(m_OrdFMin(m_Value(MatchL), m_Value(MatchR))
+ // Test inverted selects. Note, that this "inverts" the ordering, e.g.:
+ // %cmp = fcmp oge L, R
+ // %min = select %cmp R, L
+ // Given L == NaN
+ // the above is expanded to %cmp == false ==> %min = L
+ // which is true for UnordFMin, not OrdFMin, so test that:
+
+ // [OU]GE with inverted select.
+ EXPECT_FALSE(m_OrdFMin(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpOGE(L, R), R, L)));
+ EXPECT_TRUE(m_OrdFMin(m_Value(MatchL), m_Value(MatchR))
+ .match(IRB.CreateSelect(IRB.CreateFCmpUGE(L, R), R, L)));
EXPECT_EQ(L, MatchL);
EXPECT_EQ(R, MatchR);
- // Test match on OGT with inverted select.
- EXPECT_TRUE(m_OrdFMin(m_Value(MatchL), m_Value(MatchR))
+ // [OU]GT with inverted select.
+ EXPECT_FALSE(m_OrdFMin(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpOGT(L, R), R, L)));
+ EXPECT_TRUE(m_OrdFMin(m_Value(MatchL), m_Value(MatchR))
+ .match(IRB.CreateSelect(IRB.CreateFCmpUGT(L, R), R, L)));
EXPECT_EQ(L, MatchL);
EXPECT_EQ(R, MatchR);
}
@@ -130,15 +141,27 @@ TEST_F(PatternMatchTest, FloatingPointOrderedMax) {
EXPECT_FALSE(m_OrdFMax(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpOLT(L, R), L, R)));
- // Test match on OLE with inverted select.
+
+ // Test inverted selects. Note, that this "inverts" the ordering, e.g.:
+ // %cmp = fcmp ole L, R
+ // %max = select %cmp, R, L
+ // Given L == NaN,
+ // the above is expanded to %cmp == false ==> %max == L
+ // which is true for UnordFMax, not OrdFMax, so test that:
+
+ // [OU]LE with inverted select.
+ EXPECT_FALSE(m_OrdFMax(m_Value(MatchL), m_Value(MatchR))
+ .match(IRB.CreateSelect(IRB.CreateFCmpOLE(L, R), R, L)));
EXPECT_TRUE(m_OrdFMax(m_Value(MatchL), m_Value(MatchR))
- .match(IRB.CreateSelect(IRB.CreateFCmpOLE(L, R), R, L)));
+ .match(IRB.CreateSelect(IRB.CreateFCmpULE(L, R), R, L)));
EXPECT_EQ(L, MatchL);
EXPECT_EQ(R, MatchR);
- // Test match on OLT with inverted select.
+ // [OUT]LT with inverted select.
+ EXPECT_FALSE(m_OrdFMax(m_Value(MatchL), m_Value(MatchR))
+ .match(IRB.CreateSelect(IRB.CreateFCmpOLT(L, R), R, L)));
EXPECT_TRUE(m_OrdFMax(m_Value(MatchL), m_Value(MatchR))
- .match(IRB.CreateSelect(IRB.CreateFCmpOLT(L, R), R, L)));
+ .match(IRB.CreateSelect(IRB.CreateFCmpULT(L, R), R, L)));
EXPECT_EQ(L, MatchL);
EXPECT_EQ(R, MatchR);
}
@@ -169,15 +192,26 @@ TEST_F(PatternMatchTest, FloatingPointUnorderedMin) {
EXPECT_FALSE(m_UnordFMin(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpUGT(L, R), L, R)));
- // Test match on UGE with inverted select.
- EXPECT_TRUE(m_UnordFMin(m_Value(MatchL), m_Value(MatchR))
+ // Test inverted selects. Note, that this "inverts" the ordering, e.g.:
+ // %cmp = fcmp uge L, R
+ // %min = select %cmp R, L
+ // Given L == NaN
+ // the above is expanded to %cmp == true ==> %min = R
+ // which is true for OrdFMin, not UnordFMin, so test that:
+
+ // [UO]GE with inverted select.
+ EXPECT_FALSE(m_UnordFMin(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpUGE(L, R), R, L)));
+ EXPECT_TRUE(m_UnordFMin(m_Value(MatchL), m_Value(MatchR))
+ .match(IRB.CreateSelect(IRB.CreateFCmpOGE(L, R), R, L)));
EXPECT_EQ(L, MatchL);
EXPECT_EQ(R, MatchR);
- // Test match on UGT with inverted select.
- EXPECT_TRUE(m_UnordFMin(m_Value(MatchL), m_Value(MatchR))
+ // [UO]GT with inverted select.
+ EXPECT_FALSE(m_UnordFMin(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpUGT(L, R), R, L)));
+ EXPECT_TRUE(m_UnordFMin(m_Value(MatchL), m_Value(MatchR))
+ .match(IRB.CreateSelect(IRB.CreateFCmpOGT(L, R), R, L)));
EXPECT_EQ(L, MatchL);
EXPECT_EQ(R, MatchR);
}
@@ -208,15 +242,26 @@ TEST_F(PatternMatchTest, FloatingPointUnorderedMax) {
EXPECT_FALSE(m_UnordFMax(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpULT(L, R), L, R)));
- // Test match on ULE with inverted select.
- EXPECT_TRUE(m_UnordFMax(m_Value(MatchL), m_Value(MatchR))
+ // Test inverted selects. Note, that this "inverts" the ordering, e.g.:
+ // %cmp = fcmp ule L, R
+ // %max = select %cmp R, L
+ // Given L == NaN
+ // the above is expanded to %cmp == true ==> %max = R
+ // which is true for OrdFMax, not UnordFMax, so test that:
+
+ // [UO]LE with inverted select.
+ EXPECT_FALSE(m_UnordFMax(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpULE(L, R), R, L)));
+ EXPECT_TRUE(m_UnordFMax(m_Value(MatchL), m_Value(MatchR))
+ .match(IRB.CreateSelect(IRB.CreateFCmpOLE(L, R), R, L)));
EXPECT_EQ(L, MatchL);
EXPECT_EQ(R, MatchR);
- // Test match on ULT with inverted select.
- EXPECT_TRUE(m_UnordFMax(m_Value(MatchL), m_Value(MatchR))
+ // [UO]LT with inverted select.
+ EXPECT_FALSE(m_UnordFMax(m_Value(MatchL), m_Value(MatchR))
.match(IRB.CreateSelect(IRB.CreateFCmpULT(L, R), R, L)));
+ EXPECT_TRUE(m_UnordFMax(m_Value(MatchL), m_Value(MatchR))
+ .match(IRB.CreateSelect(IRB.CreateFCmpOLT(L, R), R, L)));
EXPECT_EQ(L, MatchL);
EXPECT_EQ(R, MatchR);
}