// Non-splat vector constant: check each element for a match.
unsigned NumElts = V->getType()->getVectorNumElements();
assert(NumElts != 0 && "Constant vector with no elements?");
+ bool HasNonUndefElements = false;
for (unsigned i = 0; i != NumElts; ++i) {
Constant *Elt = C->getAggregateElement(i);
if (!Elt)
auto *CI = dyn_cast<ConstantInt>(Elt);
if (!CI || !this->isValue(CI->getValue()))
return false;
+ HasNonUndefElements = true;
}
- return true;
+ return HasNonUndefElements;
}
}
return false;
// Non-splat vector constant: check each element for a match.
unsigned NumElts = V->getType()->getVectorNumElements();
assert(NumElts != 0 && "Constant vector with no elements?");
+ bool HasNonUndefElements = false;
for (unsigned i = 0; i != NumElts; ++i) {
Constant *Elt = C->getAggregateElement(i);
if (!Elt)
auto *CF = dyn_cast<ConstantFP>(Elt);
if (!CF || !this->isValue(CF->getValueAPF()))
return false;
+ HasNonUndefElements = true;
}
- return true;
+ return HasNonUndefElements;
}
}
return false;
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*>,