summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/PatternMatch.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-11-20 16:08:19 +0000
committerSanjay Patel <spatel@rotateright.com>2018-11-20 16:08:19 +0000
commitf5ead29b781fea13bdac8bf154a6a600b2adfbb4 (patch)
tree35541f7cb737a2464a69136237d69348bbc14443 /llvm/unittests/IR/PatternMatch.cpp
parent704af23db2ad56168f28d047943b780b5d95f849 (diff)
downloadbcm5719-llvm-f5ead29b781fea13bdac8bf154a6a600b2adfbb4.tar.gz
bcm5719-llvm-f5ead29b781fea13bdac8bf154a6a600b2adfbb4.zip
[PatternMatch] Handle undef vectors consistently
This patch fixes the issue noticed in D54532. The problem is that cst_pred_ty-based matchers like m_Zero() currently do not match scalar undefs (as expected), but *do* match vector undefs. This may lead to optimization inconsistencies in rare cases. There is only one existing test for which output changes, reverting the change from D53205. The reason here is that vector fsub undef, %x is no longer matched as an m_FNeg(). While I think that the new output is technically worse than the previous one, it is consistent with scalar, and I don't think it's really important either way (generally that undef should have been folded away prior to reassociation.) I've also added another test case for this issue based on InstructionSimplify. It took some effort to find that one, as in most cases undef folds are either checked first -- and in the cases where they aren't it usually happens to not make a difference in the end. This is the only case I was able to come up with. Prior to this patch the test case simplified to undef in the scalar case, but zeroinitializer in the vector case. Patch by: @nikic (Nikita Popov) Differential Revision: https://reviews.llvm.org/D54631 llvm-svn: 347318
Diffstat (limited to 'llvm/unittests/IR/PatternMatch.cpp')
-rw-r--r--llvm/unittests/IR/PatternMatch.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index 6b5686d53c6..976e42d0dbb 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -534,6 +534,62 @@ TEST_F(PatternMatchTest, VectorOps) {
EXPECT_TRUE(A == Val);
}
+TEST_F(PatternMatchTest, VectorUndefInt) {
+ Type *ScalarTy = IRB.getInt8Ty();
+ Type *VectorTy = VectorType::get(ScalarTy, 4);
+ Constant *ScalarUndef = UndefValue::get(ScalarTy);
+ Constant *VectorUndef = UndefValue::get(VectorTy);
+ Constant *ScalarZero = Constant::getNullValue(ScalarTy);
+ Constant *VectorZero = Constant::getNullValue(VectorTy);
+
+ SmallVector<Constant *, 4> Elems;
+ Elems.push_back(ScalarUndef);
+ Elems.push_back(ScalarZero);
+ Elems.push_back(ScalarUndef);
+ Elems.push_back(ScalarZero);
+ Constant *VectorZeroUndef = ConstantVector::get(Elems);
+
+ EXPECT_TRUE(match(ScalarUndef, m_Undef()));
+ EXPECT_TRUE(match(VectorUndef, m_Undef()));
+ EXPECT_FALSE(match(ScalarZero, m_Undef()));
+ EXPECT_FALSE(match(VectorZero, m_Undef()));
+ EXPECT_FALSE(match(VectorZeroUndef, m_Undef()));
+
+ EXPECT_FALSE(match(ScalarUndef, m_Zero()));
+ EXPECT_FALSE(match(VectorUndef, m_Zero()));
+ EXPECT_TRUE(match(ScalarZero, m_Zero()));
+ EXPECT_TRUE(match(VectorZero, m_Zero()));
+ EXPECT_TRUE(match(VectorZeroUndef, m_Zero()));
+}
+
+TEST_F(PatternMatchTest, VectorUndefFloat) {
+ Type *ScalarTy = IRB.getFloatTy();
+ Type *VectorTy = VectorType::get(ScalarTy, 4);
+ Constant *ScalarUndef = UndefValue::get(ScalarTy);
+ Constant *VectorUndef = UndefValue::get(VectorTy);
+ Constant *ScalarZero = Constant::getNullValue(ScalarTy);
+ Constant *VectorZero = Constant::getNullValue(VectorTy);
+
+ SmallVector<Constant *, 4> Elems;
+ Elems.push_back(ScalarUndef);
+ Elems.push_back(ScalarZero);
+ Elems.push_back(ScalarUndef);
+ Elems.push_back(ScalarZero);
+ Constant *VectorZeroUndef = ConstantVector::get(Elems);
+
+ EXPECT_TRUE(match(ScalarUndef, m_Undef()));
+ EXPECT_TRUE(match(VectorUndef, m_Undef()));
+ EXPECT_FALSE(match(ScalarZero, m_Undef()));
+ EXPECT_FALSE(match(VectorZero, m_Undef()));
+ EXPECT_FALSE(match(VectorZeroUndef, m_Undef()));
+
+ EXPECT_FALSE(match(ScalarUndef, m_AnyZeroFP()));
+ EXPECT_FALSE(match(VectorUndef, m_AnyZeroFP()));
+ EXPECT_TRUE(match(ScalarZero, m_AnyZeroFP()));
+ EXPECT_TRUE(match(VectorZero, m_AnyZeroFP()));
+ EXPECT_TRUE(match(VectorZeroUndef, m_AnyZeroFP()));
+}
+
template <typename T> struct MutableConstTest : PatternMatchTest { };
typedef ::testing::Types<std::tuple<Value*, Instruction*>,
OpenPOWER on IntegriCloud