Skip to content

Commit c77ac06

Browse files
author
Aidan
committed
Updated element-wise arrayref cmps to not use overridden == but std::equal(). Readded cmp for capture test. Removed const for ArrayRef. Correctly capture arrayref in m_Shuffle varient. Changed m_Value(V) to m_Value, as vec contents not needed.
1 parent b365d5b commit c77ac06

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

llvm/include/llvm/CodeGen/SDPatternMatch.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -545,15 +545,16 @@ template <typename T0, typename T1> struct SDShuffle_match {
545545
T0 Op1;
546546
T1 Op2;
547547

548-
const ArrayRef<int> *MaskRef;
548+
ArrayRef<int> &CapturedMask;
549549

550550
// capturing mask
551-
SDShuffle_match(const T0 &Op1, const T1 &Op2, const ArrayRef<int> &MaskRef)
552-
: Op1(Op1), Op2(Op2), MaskRef(&MaskRef) {}
551+
SDShuffle_match(const T0 &Op1, const T1 &Op2, ArrayRef<int> &MaskRef)
552+
: Op1(Op1), Op2(Op2), CapturedMask(MaskRef) {}
553553

554554
template <typename MatchContext>
555555
bool match(const MatchContext &Ctx, SDValue N) {
556556
if (auto *I = dyn_cast<ShuffleVectorSDNode>(N)) {
557+
CapturedMask = I->getMask();
557558
return Op1.match(Ctx, I->getOperand(0)) &&
558559
Op2.match(Ctx, I->getOperand(1));
559560
}
@@ -567,14 +568,16 @@ template <typename T0, typename T1> struct SDShuffle_maskMatch {
567568
T1 Op2;
568569
ArrayRef<int> SpecificMask;
569570

570-
SDShuffle_maskMatch(const T0 &Op1, const T1 &Op2, const ArrayRef<int> Mask)
571+
SDShuffle_maskMatch(const T0 &Op1, const T1 &Op2, ArrayRef<int> Mask)
571572
: Op1(Op1), Op2(Op2), SpecificMask(Mask) {}
572573

573574
template <typename MatchContext>
574575
bool match(const MatchContext &Ctx, SDValue N) {
575576
if (auto *I = dyn_cast<ShuffleVectorSDNode>(N)) {
576577
return Op1.match(Ctx, I->getOperand(0)) &&
577-
Op2.match(Ctx, I->getOperand(1)) && I->getMask() == SpecificMask;
578+
Op2.match(Ctx, I->getOperand(1)) &&
579+
std::equal(SpecificMask.begin(), SpecificMask.end(),
580+
I->getMask().begin(), I->getMask().end());
578581
}
579582
return false;
580583
}
@@ -831,14 +834,13 @@ inline BinaryOpc_match<LHS, RHS> m_FRem(const LHS &L, const RHS &R) {
831834

832835
template <typename V1_t, typename V2_t>
833836
inline SDShuffle_match<V1_t, V2_t> m_Shuffle(const V1_t &v1, const V2_t &v2,
834-
const ArrayRef<int> &maskRef) {
835-
return SDShuffle_match<V1_t, V2_t>(v1, v2, maskRef);
837+
ArrayRef<int> &mask) {
838+
return SDShuffle_match<V1_t, V2_t>(v1, v2, mask);
836839
}
837840

838841
template <typename V1_t, typename V2_t>
839842
inline SDShuffle_maskMatch<V1_t, V2_t>
840-
m_ShuffleSpecificMask(const V1_t &v1, const V2_t &v2,
841-
const ArrayRef<int> mask) {
843+
m_ShuffleSpecificMask(const V1_t &v1, const V2_t &v2, ArrayRef<int> mask) {
842844
return SDShuffle_maskMatch<V1_t, V2_t>(v1, v2, mask);
843845
}
844846

llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ TEST_F(SelectionDAGPatternMatchTest, matchVecShuffle) {
133133

134134
using namespace SDPatternMatch;
135135
EXPECT_TRUE(sd_match(VecShuffleWithMask,
136-
m_Shuffle(m_Value(V0), m_Value(V1), CapturedMask)));
137-
EXPECT_TRUE(
138-
sd_match(VecShuffleWithMask,
139-
m_ShuffleSpecificMask(m_Value(V0), m_Value(V1), MaskData)));
136+
m_Shuffle(m_Value(), m_Value(), CapturedMask)));
137+
EXPECT_TRUE(sd_match(VecShuffleWithMask,
138+
m_ShuffleSpecificMask(m_Value(), m_Value(), MaskData)));
139+
EXPECT_TRUE(std::equal(MaskData.begin(), MaskData.end(), CapturedMask.begin(),
140+
CapturedMask.end()));
140141
}
141142

142143
TEST_F(SelectionDAGPatternMatchTest, matchTernaryOp) {

0 commit comments

Comments
 (0)