[llvm] c1e159e - [IR] fix Constant::isElementWiseEqual() to allow for all undef elements compare
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 05:33:52 PST 2020
Author: Sanjay Patel
Date: 2020-01-17T08:31:16-05:00
New Revision: c1e159ef6eb0095b78d08594f02f511c69d9a64b
URL: https://github.com/llvm/llvm-project/commit/c1e159ef6eb0095b78d08594f02f511c69d9a64b
DIFF: https://github.com/llvm/llvm-project/commit/c1e159ef6eb0095b78d08594f02f511c69d9a64b.diff
LOG: [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.
Added:
Modified:
llvm/lib/IR/Constants.cpp
llvm/unittests/IR/ConstantsTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 93d406fa2eb0..79c302867369 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -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 {
diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp
index 7154f35ccbd4..5b5e8d154c21 100644
--- a/llvm/unittests/IR/ConstantsTest.cpp
+++ b/llvm/unittests/IR/ConstantsTest.cpp
@@ -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));
More information about the llvm-commits
mailing list