[PATCH] D137170: [PatternMatch] don't match a scalar select of bool vectors as a logical-and or logical-or
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 09:31:32 PDT 2022
spatel created this revision.
spatel added reviewers: nikic, aqjune, zhendongsu.
Herald added a subscriber: mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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 <https://github.com/llvm/llvm-project/issues/58552>. The fold(s) responsible for that crash (D101807 <https://reviews.llvm.org/D101807>, D101375 <https://reviews.llvm.org/D101375>) don't use the matchers yet, but they probably should.
https://reviews.llvm.org/D137170
Files:
llvm/include/llvm/IR/PatternMatch.h
llvm/unittests/IR/PatternMatch.cpp
Index: llvm/unittests/IR/PatternMatch.cpp
===================================================================
--- llvm/unittests/IR/PatternMatch.cpp
+++ llvm/unittests/IR/PatternMatch.cpp
@@ -1730,10 +1730,12 @@
// 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) {
Index: llvm/include/llvm/IR/PatternMatch.h
===================================================================
--- llvm/include/llvm/IR/PatternMatch.h
+++ llvm/include/llvm/IR/PatternMatch.h
@@ -2513,6 +2513,12 @@
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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137170.472326.patch
Type: text/x-patch
Size: 1580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221101/ebaad1aa/attachment.bin>
More information about the llvm-commits
mailing list