Skip to content

Commit 80e64f6

Browse files
author
Aidan
committed
ArrayRef passed by value. Added test, may remove another later.
1 parent 53497e7 commit 80e64f6

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

llvm/include/llvm/CodeGen/SDPatternMatch.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,19 +565,18 @@ template <typename T0, typename T1, typename T2> struct SDShuffle_match {
565565
return false;
566566
}
567567
};
568-
569568
struct m_Mask {
570-
ArrayRef<int> &MaskRef;
571-
m_Mask(ArrayRef<int> &MaskRef) : MaskRef(MaskRef) {}
569+
ArrayRef<int> MaskRef;
570+
m_Mask(ArrayRef<int> MaskRef) : MaskRef(MaskRef) {}
572571
bool match(ArrayRef<int> Mask) {
573572
MaskRef = Mask;
574573
return true;
575574
}
576575
};
577576

578577
struct m_SpecificMask {
579-
ArrayRef<int> &MaskRef;
580-
m_SpecificMask(ArrayRef<int> &MaskRef) : MaskRef(MaskRef) {}
578+
ArrayRef<int> MaskRef;
579+
m_SpecificMask(ArrayRef<int> MaskRef) : MaskRef(MaskRef) {}
581580
bool match(ArrayRef<int> Mask) { return MaskRef == Mask; }
582581
};
583582

llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ TEST_F(SelectionDAGPatternMatchTest, matchVecShuffle) {
125125
auto VInt32VT = EVT::getVectorVT(Context, Int32VT, 4);
126126
const std::array<int, 4> MaskData = {2, 0, 3, 1};
127127
const std::array<int, 4> OtherMaskData = {1, 2, 3, 4};
128-
ArrayRef<int> Mask(MaskData);
129-
ArrayRef<int> CapturedMask;
128+
ArrayRef<int> CapturedMask(MaskData);
130129

131130
SDValue V0 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, VInt32VT);
132131
SDValue V1 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 2, VInt32VT);
@@ -137,8 +136,12 @@ TEST_F(SelectionDAGPatternMatchTest, matchVecShuffle) {
137136
EXPECT_TRUE(sd_match(VecShuffleWithMask, m_Shuffle(m_Value(), m_Value())));
138137
EXPECT_TRUE(sd_match(VecShuffleWithMask,
139138
m_Shuffle(m_Value(), m_Value(), m_Mask(CapturedMask))));
140-
EXPECT_TRUE(sd_match(VecShuffleWithMask,
141-
m_Shuffle(m_Value(), m_Value(), m_SpecificMask(Mask))));
139+
EXPECT_TRUE(
140+
sd_match(VecShuffleWithMask,
141+
m_Shuffle(m_Value(), m_Value(), m_SpecificMask(MaskData))));
142+
EXPECT_FALSE(
143+
sd_match(VecShuffleWithMask,
144+
m_Shuffle(m_Value(), m_Value(), m_SpecificMask(OtherMaskData))));
142145
EXPECT_TRUE(std::equal(MaskData.begin(), MaskData.end(), CapturedMask.begin(),
143146
CapturedMask.end()));
144147
EXPECT_FALSE(std::equal(OtherMaskData.begin(), OtherMaskData.end(),

0 commit comments

Comments
 (0)