[llvm] 72ba248 - [PatternMatch] don't match a scalar select of bool vectors as a logical-and or logical-or
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 11:50:30 PDT 2022
Author: Sanjay Patel
Date: 2022-11-01T14:50:18-04:00
New Revision: 72ba2489f2c7b0a911bd23e50aaaca6eae9a183e
URL: https://github.com/llvm/llvm-project/commit/72ba2489f2c7b0a911bd23e50aaaca6eae9a183e
DIFF: https://github.com/llvm/llvm-project/commit/72ba2489f2c7b0a911bd23e50aaaca6eae9a183e.diff
LOG: [PatternMatch] don't match a scalar select of bool vectors as a logical-and or logical-or
Most folds based on these matchers already check to make sure the
condition type is the same as the select type, and it seems unlikely
that a fold would want to handle a scalar-select-of-vectors pattern
(there are no regression tests for it).
This is a preliminary step for fixing #issue 58552. The fold(s)
responsible for that crash (D101807, D101375) don't use the matchers
yet, but they probably should.
Differential Revision: https://reviews.llvm.org/D137170
Added:
Modified:
llvm/include/llvm/IR/PatternMatch.h
llvm/unittests/IR/PatternMatch.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 31ff63c8b6603..2901c6456c998 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2513,6 +2513,12 @@ struct LogicalOp_match {
auto *Cond = Select->getCondition();
auto *TVal = Select->getTrueValue();
auto *FVal = Select->getFalseValue();
+
+ // Don't match a scalar select of bool vectors.
+ // Transforms expect a single type for operands if this matches.
+ if (Cond->getType() != Select->getType())
+ return false;
+
if (Opcode == Instruction::And) {
auto *C = dyn_cast<Constant>(FVal);
if (C && C->isNullValue())
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index d2ec259ec8287..ab35df016cdda 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -1730,10 +1730,12 @@ TEST_F(PatternMatchTest, VectorLogicalSelects) {
// select i1 Scalar, <3 x i1> <i1 1, i1 1, i1 1>, <3 x i1> Vector
Value *MixedTypeOr = IRB.CreateSelect(Scalar, T, Vector);
+ // We allow matching a real vector logical select,
+ // but not a scalar select of vector bools.
EXPECT_TRUE(match(VecAnd, m_LogicalAnd(m_Value(), m_Value())));
- EXPECT_TRUE(match(MixedTypeAnd, m_LogicalAnd(m_Value(), m_Value())));
+ EXPECT_FALSE(match(MixedTypeAnd, m_LogicalAnd(m_Value(), m_Value())));
EXPECT_TRUE(match(VecOr, m_LogicalOr(m_Value(), m_Value())));
- EXPECT_TRUE(match(MixedTypeOr, m_LogicalOr(m_Value(), m_Value())));
+ EXPECT_FALSE(match(MixedTypeOr, m_LogicalOr(m_Value(), m_Value())));
}
TEST_F(PatternMatchTest, VScale) {
More information about the llvm-commits
mailing list