[IR] fix Constant::isElementWiseEqual() to allow for all undef elements compare

We could argue that match() should be more flexible here,
but I'm not sure what impact that would have on existing code.
This commit is contained in:
Sanjay Patel 2020-01-17 08:31:16 -05:00
parent ffd3e1607d
commit c1e159ef6e
2 changed files with 3 additions and 2 deletions

View File

@ -296,7 +296,8 @@ bool Constant::isElementWiseEqual(Value *Y) const {
Type *IntTy = VectorType::getInteger(cast<VectorType>(Ty));
Constant *C0 = ConstantExpr::getBitCast(const_cast<Constant *>(this), IntTy);
Constant *C1 = ConstantExpr::getBitCast(cast<Constant>(Y), IntTy);
return match(ConstantExpr::getICmp(ICmpInst::ICMP_EQ, C0, C1), m_One());
Constant *CmpEq = ConstantExpr::getICmp(ICmpInst::ICMP_EQ, C0, C1);
return isa<UndefValue>(CmpEq) || match(CmpEq, m_One());
}
bool Constant::containsUndefElement() const {

View File

@ -620,7 +620,7 @@ TEST(ConstantsTest, isElementWiseEqual) {
EXPECT_TRUE(CF1211->isElementWiseEqual(CF12U1));
EXPECT_TRUE(CF12U1->isElementWiseEqual(CF1211));
EXPECT_FALSE(CFUU1U->isElementWiseEqual(CF12U1)); // FIXME - all lanes compare as undef
EXPECT_TRUE(CFUU1U->isElementWiseEqual(CF12U1));
EXPECT_FALSE(CF12U2->isElementWiseEqual(CF12U1));
EXPECT_FALSE(CF12U1->isElementWiseEqual(CF12U2));