Skip to content

Commit 05b907f

Browse files
authored
[VectorCombine] foldShuffleOfShuffles - allow fold with only single shuffle operand. (#119354)
foldShuffleOfShuffles already handles "shuffle (shuffle x, undef), (shuffle y, undef)" patterns, this patch relaxes the requirement so it can handle cases where only a single operand is a shuffle (and the other can be any other value and will be kept in place). Fixes #86068
1 parent 740861d commit 05b907f

File tree

4 files changed

+62
-72
lines changed

4 files changed

+62
-72
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,21 +1706,30 @@ bool VectorCombine::foldShuffleOfCastops(Instruction &I) {
17061706
return true;
17071707
}
17081708

1709-
/// Try to convert "shuffle (shuffle x, undef), (shuffle y, undef)"
1709+
/// Try to convert any of:
1710+
/// "shuffle (shuffle x, undef), (shuffle y, undef)"
1711+
/// "shuffle (shuffle x, undef), y"
1712+
/// "shuffle x, (shuffle y, undef)"
17101713
/// into "shuffle x, y".
17111714
bool VectorCombine::foldShuffleOfShuffles(Instruction &I) {
1712-
Value *V0, *V1;
1713-
UndefValue *U0, *U1;
1714-
ArrayRef<int> OuterMask, InnerMask0, InnerMask1;
1715+
ArrayRef<int> OuterMask;
1716+
Value *OuterV0, *OuterV1;
17151717
if (!match(&I,
1716-
m_Shuffle(
1717-
m_Shuffle(m_Value(V0), m_UndefValue(U0), m_Mask(InnerMask0)),
1718-
m_Shuffle(m_Value(V1), m_UndefValue(U1), m_Mask(InnerMask1)),
1719-
m_Mask(OuterMask))))
1718+
m_Shuffle(m_Value(OuterV0), m_Value(OuterV1), m_Mask(OuterMask))))
17201719
return false;
17211720

1722-
auto *ShufI0 = dyn_cast<Instruction>(I.getOperand(0));
1723-
auto *ShufI1 = dyn_cast<Instruction>(I.getOperand(1));
1721+
ArrayRef<int> InnerMask0, InnerMask1;
1722+
Value *V0 = nullptr, *V1 = nullptr;
1723+
UndefValue *U0 = nullptr, *U1 = nullptr;
1724+
bool Match0 = match(
1725+
OuterV0, m_Shuffle(m_Value(V0), m_UndefValue(U0), m_Mask(InnerMask0)));
1726+
bool Match1 = match(
1727+
OuterV1, m_Shuffle(m_Value(V1), m_UndefValue(U1), m_Mask(InnerMask1)));
1728+
if (!Match0 && !Match1)
1729+
return false;
1730+
1731+
V0 = Match0 ? V0 : OuterV0;
1732+
V1 = Match1 ? V1 : OuterV1;
17241733
auto *ShuffleDstTy = dyn_cast<FixedVectorType>(I.getType());
17251734
auto *ShuffleSrcTy = dyn_cast<FixedVectorType>(V0->getType());
17261735
auto *ShuffleImmTy = dyn_cast<FixedVectorType>(I.getOperand(0)->getType());
@@ -1732,22 +1741,25 @@ bool VectorCombine::foldShuffleOfShuffles(Instruction &I) {
17321741
unsigned NumImmElts = ShuffleImmTy->getNumElements();
17331742

17341743
// Bail if either inner masks reference a RHS undef arg.
1735-
if ((!isa<PoisonValue>(U0) &&
1744+
if ((Match0 && !isa<PoisonValue>(U0) &&
17361745
any_of(InnerMask0, [&](int M) { return M >= (int)NumSrcElts; })) ||
1737-
(!isa<PoisonValue>(U1) &&
1746+
(Match1 && !isa<PoisonValue>(U1) &&
17381747
any_of(InnerMask1, [&](int M) { return M >= (int)NumSrcElts; })))
17391748
return false;
17401749

17411750
// Merge shuffles - replace index to the RHS poison arg with PoisonMaskElem,
17421751
SmallVector<int, 16> NewMask(OuterMask);
17431752
for (int &M : NewMask) {
17441753
if (0 <= M && M < (int)NumImmElts) {
1745-
M = (InnerMask0[M] >= (int)NumSrcElts) ? PoisonMaskElem : InnerMask0[M];
1754+
if (Match0)
1755+
M = (InnerMask0[M] >= (int)NumSrcElts) ? PoisonMaskElem : InnerMask0[M];
17461756
} else if (M >= (int)NumImmElts) {
1747-
if (InnerMask1[M - NumImmElts] >= (int)NumSrcElts)
1748-
M = PoisonMaskElem;
1749-
else
1750-
M = InnerMask1[M - NumImmElts] + (V0 == V1 ? 0 : NumSrcElts);
1757+
if (Match1) {
1758+
if (InnerMask1[M - NumImmElts] >= (int)NumSrcElts)
1759+
M = PoisonMaskElem;
1760+
else
1761+
M = InnerMask1[M - NumImmElts] + (V0 == V1 ? 0 : NumSrcElts);
1762+
}
17511763
}
17521764
}
17531765

@@ -1758,23 +1770,30 @@ bool VectorCombine::foldShuffleOfShuffles(Instruction &I) {
17581770
}
17591771

17601772
// Try to merge the shuffles if the new shuffle is not costly.
1761-
InstructionCost InnerCost0 =
1762-
TTI.getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc, ShuffleSrcTy,
1763-
InnerMask0, CostKind, 0, nullptr, {V0, U0}, ShufI0);
1764-
InstructionCost InnerCost1 =
1765-
TTI.getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc, ShuffleSrcTy,
1766-
InnerMask1, CostKind, 0, nullptr, {V1, U1}, ShufI1);
1767-
InstructionCost OuterCost =
1768-
TTI.getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, ShuffleImmTy,
1769-
OuterMask, CostKind, 0, nullptr, {ShufI0, ShufI1}, &I);
1773+
InstructionCost InnerCost0 = 0;
1774+
if (Match0)
1775+
InnerCost0 = TTI.getShuffleCost(
1776+
TargetTransformInfo::SK_PermuteSingleSrc, ShuffleSrcTy, InnerMask0,
1777+
CostKind, 0, nullptr, {V0, U0}, cast<ShuffleVectorInst>(OuterV0));
1778+
1779+
InstructionCost InnerCost1 = 0;
1780+
if (Match1)
1781+
InnerCost1 = TTI.getShuffleCost(
1782+
TargetTransformInfo::SK_PermuteSingleSrc, ShuffleSrcTy, InnerMask1,
1783+
CostKind, 0, nullptr, {V1, U1}, cast<ShuffleVectorInst>(OuterV1));
1784+
1785+
InstructionCost OuterCost = TTI.getShuffleCost(
1786+
TargetTransformInfo::SK_PermuteTwoSrc, ShuffleImmTy, OuterMask, CostKind,
1787+
0, nullptr, {OuterV0, OuterV1}, &I);
1788+
17701789
InstructionCost OldCost = InnerCost0 + InnerCost1 + OuterCost;
17711790

17721791
InstructionCost NewCost =
17731792
TTI.getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, ShuffleSrcTy,
17741793
NewMask, CostKind, 0, nullptr, {V0, V1});
1775-
if (!ShufI0->hasOneUse())
1794+
if (!OuterV0->hasOneUse())
17761795
NewCost += InnerCost0;
1777-
if (!ShufI1->hasOneUse())
1796+
if (!OuterV1->hasOneUse())
17781797
NewCost += InnerCost1;
17791798

17801799
LLVM_DEBUG(dbgs() << "Found a shuffle feeding two shuffles: " << I

llvm/test/Transforms/PhaseOrdering/X86/shuffle-inseltpoison.ll

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,11 @@ define <4 x i32> @shuffle_8_add_32_masks_are_eq_and_can_be_converted_up(<16 x i8
159159
}
160160

161161
; shuffle<8 x i16>( bitcast<8 x i16>( shuffle<4 x i32>(v)))
162-
; TODO: Squash shuffles and widen type?
163162

164163
define <8 x i16> @shuffle_32_bitcast_16_shuffle_16_can_be_converted_up(<4 x i32> %v1) {
165164
; CHECK-LABEL: @shuffle_32_bitcast_16_shuffle_16_can_be_converted_up(
166165
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32> [[V1:%.*]] to <8 x i16>
167-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
168-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[BC1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
166+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 2, i32 3, i32 0, i32 1, i32 6, i32 7, i32 4, i32 5>
169167
; CHECK-NEXT: ret <8 x i16> [[SHUFFLE2]]
170168
;
171169
%shuffle1 = shufflevector <4 x i32> %v1, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
@@ -175,13 +173,11 @@ define <8 x i16> @shuffle_32_bitcast_16_shuffle_16_can_be_converted_up(<4 x i32>
175173
}
176174

177175
; shuffle<8 x i16>( bitcast<8 x i16>( shuffle<4 x i32>(v)))
178-
; TODO: Squash shuffles?
179176

180177
define <8 x i16> @shuffle_32_bitcast_16_shuffle_16_can_not_be_converted_up(<4 x i32> %v1) {
181178
; CHECK-LABEL: @shuffle_32_bitcast_16_shuffle_16_can_not_be_converted_up(
182179
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32> [[V1:%.*]] to <8 x i16>
183-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
184-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[BC1]], <8 x i16> poison, <8 x i32> <i32 5, i32 4, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
180+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 3, i32 2, i32 0, i32 1, i32 4, i32 5, i32 6, i32 7>
185181
; CHECK-NEXT: ret <8 x i16> [[SHUFFLE2]]
186182
;
187183
%shuffle1 = shufflevector <4 x i32> %v1, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
@@ -191,13 +187,11 @@ define <8 x i16> @shuffle_32_bitcast_16_shuffle_16_can_not_be_converted_up(<4 x
191187
}
192188

193189
; shuffle<16 x i8>( bitcast<16 x i8>( shuffle<4 x i32>(v)))
194-
; TODO: Squash shuffles and widen type?
195190

196191
define <16 x i8> @shuffle_32_bitcast_8_shuffle_8_can_be_converted_up(<4 x i32> %v1) {
197192
; CHECK-LABEL: @shuffle_32_bitcast_8_shuffle_8_can_be_converted_up(
198193
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32> [[V1:%.*]] to <16 x i8>
199-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
200-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <16 x i8> [[BC1]], <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
194+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> poison, <16 x i32> <i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3, i32 12, i32 13, i32 14, i32 15, i32 8, i32 9, i32 10, i32 11>
201195
; CHECK-NEXT: ret <16 x i8> [[SHUFFLE2]]
202196
;
203197
%shuffle1 = shufflevector <4 x i32> %v1, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
@@ -207,13 +201,11 @@ define <16 x i8> @shuffle_32_bitcast_8_shuffle_8_can_be_converted_up(<4 x i32> %
207201
}
208202

209203
; shuffle<16 x i8>( bitcast<16 x i8>( shuffle<4 x i32>(v)))
210-
; TODO: Squash shuffles?
211204

212205
define <16 x i8> @shuffle_32_bitcast_8_shuffle_8_can_not_be_converted_up(<4 x i32> %v1) {
213206
; CHECK-LABEL: @shuffle_32_bitcast_8_shuffle_8_can_not_be_converted_up(
214207
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32> [[V1:%.*]] to <16 x i8>
215-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
216-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <16 x i8> [[BC1]], <16 x i8> poison, <16 x i32> <i32 5, i32 4, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
208+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> poison, <16 x i32> <i32 13, i32 12, i32 14, i32 15, i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
217209
; CHECK-NEXT: ret <16 x i8> [[SHUFFLE2]]
218210
;
219211
%shuffle1 = shufflevector <4 x i32> %v1, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
@@ -223,13 +215,11 @@ define <16 x i8> @shuffle_32_bitcast_8_shuffle_8_can_not_be_converted_up(<4 x i3
223215
}
224216

225217
; shuffle<4 x i32>( bitcast<4 x i32>( shuffle<16 x i8>(v)))
226-
; TODO: squash shuffles?
227218

228219
define <4 x i32> @shuffle_8_bitcast_32_shuffle_32_can_be_converted_up(<16 x i8> %v1) {
229220
; CHECK-LABEL: @shuffle_8_bitcast_32_shuffle_32_can_be_converted_up(
230221
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <16 x i8> [[V1:%.*]] to <4 x i32>
231-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
232-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <4 x i32> [[BC1]], <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
222+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2>
233223
; CHECK-NEXT: ret <4 x i32> [[SHUFFLE2]]
234224
;
235225
%shuffle1 = shufflevector <16 x i8> %v1, <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
@@ -239,13 +229,11 @@ define <4 x i32> @shuffle_8_bitcast_32_shuffle_32_can_be_converted_up(<16 x i8>
239229
}
240230

241231
; shuffle<4 x i32>( bitcast<4 x i32>( shuffle<8 x i16>(v)))
242-
; TODO: squash shuffles?
243232

244233
define <4 x i32> @shuffle_16_bitcast_32_shuffle_32_can_be_converted_up(<8 x i16> %v1) {
245234
; CHECK-LABEL: @shuffle_16_bitcast_32_shuffle_32_can_be_converted_up(
246235
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i16> [[V1:%.*]] to <4 x i32>
247-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
248-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <4 x i32> [[BC1]], <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
236+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2>
249237
; CHECK-NEXT: ret <4 x i32> [[SHUFFLE2]]
250238
;
251239
%shuffle1 = shufflevector <8 x i16> %v1, <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
@@ -287,13 +275,11 @@ define <4 x i32> @shuffle_16_bitcast_32_shuffle_32_can_not_be_converted_up(<8 x
287275
}
288276

289277
; shuffle<8 x i16>( bitcast<8 x i16>( shuffle<16 x i8>(v)))
290-
; TODO: squash shuffles and widen type?
291278

292279
define <8 x i16> @shuffle_8_bitcast_16_shuffle_16_can__be_converted_up(<16 x i8> %v1) {
293280
; CHECK-LABEL: @shuffle_8_bitcast_16_shuffle_16_can__be_converted_up(
294281
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <16 x i8> [[V1:%.*]] to <8 x i16>
295-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
296-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[BC1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
282+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 2, i32 3, i32 0, i32 1, i32 6, i32 7, i32 4, i32 5>
297283
; CHECK-NEXT: ret <8 x i16> [[SHUFFLE2]]
298284
;
299285
%shuffle1 = shufflevector <16 x i8> %v1, <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>

llvm/test/Transforms/PhaseOrdering/X86/shuffle.ll

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,11 @@ define <4 x i32> @shuffle_8_add_32_masks_are_eq_and_can_be_converted_up(<16 x i8
159159
}
160160

161161
; shuffle<8 x i16>( bitcast<8 x i16>( shuffle<4 x i32>(v)))
162-
; TODO: Squash shuffles and widen type?
163162

164163
define <8 x i16> @shuffle_32_bitcast_16_shuffle_16_can_be_converted_up(<4 x i32> %v1) {
165164
; CHECK-LABEL: @shuffle_32_bitcast_16_shuffle_16_can_be_converted_up(
166165
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32> [[V1:%.*]] to <8 x i16>
167-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
168-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[BC1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
166+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 2, i32 3, i32 0, i32 1, i32 6, i32 7, i32 4, i32 5>
169167
; CHECK-NEXT: ret <8 x i16> [[SHUFFLE2]]
170168
;
171169
%shuffle1 = shufflevector <4 x i32> %v1, <4 x i32> undef, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
@@ -175,13 +173,11 @@ define <8 x i16> @shuffle_32_bitcast_16_shuffle_16_can_be_converted_up(<4 x i32>
175173
}
176174

177175
; shuffle<8 x i16>( bitcast<8 x i16>( shuffle<4 x i32>(v)))
178-
; TODO: Squash shuffles?
179176

180177
define <8 x i16> @shuffle_32_bitcast_16_shuffle_16_can_not_be_converted_up(<4 x i32> %v1) {
181178
; CHECK-LABEL: @shuffle_32_bitcast_16_shuffle_16_can_not_be_converted_up(
182179
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32> [[V1:%.*]] to <8 x i16>
183-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
184-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[BC1]], <8 x i16> poison, <8 x i32> <i32 5, i32 4, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
180+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 3, i32 2, i32 0, i32 1, i32 4, i32 5, i32 6, i32 7>
185181
; CHECK-NEXT: ret <8 x i16> [[SHUFFLE2]]
186182
;
187183
%shuffle1 = shufflevector <4 x i32> %v1, <4 x i32> undef, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
@@ -191,13 +187,11 @@ define <8 x i16> @shuffle_32_bitcast_16_shuffle_16_can_not_be_converted_up(<4 x
191187
}
192188

193189
; shuffle<16 x i8>( bitcast<16 x i8>( shuffle<4 x i32>(v)))
194-
; TODO: Squash shuffles and widen type?
195190

196191
define <16 x i8> @shuffle_32_bitcast_8_shuffle_8_can_be_converted_up(<4 x i32> %v1) {
197192
; CHECK-LABEL: @shuffle_32_bitcast_8_shuffle_8_can_be_converted_up(
198193
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32> [[V1:%.*]] to <16 x i8>
199-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
200-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <16 x i8> [[BC1]], <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
194+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> poison, <16 x i32> <i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3, i32 12, i32 13, i32 14, i32 15, i32 8, i32 9, i32 10, i32 11>
201195
; CHECK-NEXT: ret <16 x i8> [[SHUFFLE2]]
202196
;
203197
%shuffle1 = shufflevector <4 x i32> %v1, <4 x i32> undef, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
@@ -207,13 +201,11 @@ define <16 x i8> @shuffle_32_bitcast_8_shuffle_8_can_be_converted_up(<4 x i32> %
207201
}
208202

209203
; shuffle<16 x i8>( bitcast<16 x i8>( shuffle<4 x i32>(v)))
210-
; TODO: Squash shuffles?
211204

212205
define <16 x i8> @shuffle_32_bitcast_8_shuffle_8_can_not_be_converted_up(<4 x i32> %v1) {
213206
; CHECK-LABEL: @shuffle_32_bitcast_8_shuffle_8_can_not_be_converted_up(
214207
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32> [[V1:%.*]] to <16 x i8>
215-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
216-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <16 x i8> [[BC1]], <16 x i8> poison, <16 x i32> <i32 5, i32 4, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
208+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <16 x i8> [[TMP1]], <16 x i8> poison, <16 x i32> <i32 13, i32 12, i32 14, i32 15, i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
217209
; CHECK-NEXT: ret <16 x i8> [[SHUFFLE2]]
218210
;
219211
%shuffle1 = shufflevector <4 x i32> %v1, <4 x i32> undef, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
@@ -223,13 +215,11 @@ define <16 x i8> @shuffle_32_bitcast_8_shuffle_8_can_not_be_converted_up(<4 x i3
223215
}
224216

225217
; shuffle<4 x i32>( bitcast<4 x i32>( shuffle<16 x i8>(v)))
226-
; TODO: squash shuffles?
227218

228219
define <4 x i32> @shuffle_8_bitcast_32_shuffle_32_can_be_converted_up(<16 x i8> %v1) {
229220
; CHECK-LABEL: @shuffle_8_bitcast_32_shuffle_32_can_be_converted_up(
230221
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <16 x i8> [[V1:%.*]] to <4 x i32>
231-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
232-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <4 x i32> [[BC1]], <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
222+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2>
233223
; CHECK-NEXT: ret <4 x i32> [[SHUFFLE2]]
234224
;
235225
%shuffle1 = shufflevector <16 x i8> %v1, <16 x i8> undef, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
@@ -239,13 +229,11 @@ define <4 x i32> @shuffle_8_bitcast_32_shuffle_32_can_be_converted_up(<16 x i8>
239229
}
240230

241231
; shuffle<4 x i32>( bitcast<4 x i32>( shuffle<8 x i16>(v)))
242-
; TODO: squash shuffles?
243232

244233
define <4 x i32> @shuffle_16_bitcast_32_shuffle_32_can_be_converted_up(<8 x i16> %v1) {
245234
; CHECK-LABEL: @shuffle_16_bitcast_32_shuffle_32_can_be_converted_up(
246235
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i16> [[V1:%.*]] to <4 x i32>
247-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
248-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <4 x i32> [[BC1]], <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 1, i32 0>
236+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2>
249237
; CHECK-NEXT: ret <4 x i32> [[SHUFFLE2]]
250238
;
251239
%shuffle1 = shufflevector <8 x i16> %v1, <8 x i16> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
@@ -287,13 +275,11 @@ define <4 x i32> @shuffle_16_bitcast_32_shuffle_32_can_not_be_converted_up(<8 x
287275
}
288276

289277
; shuffle<8 x i16>( bitcast<8 x i16>( shuffle<16 x i8>(v)))
290-
; TODO: squash shuffles and widen type?
291278

292279
define <8 x i16> @shuffle_8_bitcast_16_shuffle_16_can__be_converted_up(<16 x i8> %v1) {
293280
; CHECK-LABEL: @shuffle_8_bitcast_16_shuffle_16_can__be_converted_up(
294281
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <16 x i8> [[V1:%.*]] to <8 x i16>
295-
; CHECK-NEXT: [[BC1:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
296-
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[BC1]], <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
282+
; CHECK-NEXT: [[SHUFFLE2:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 2, i32 3, i32 0, i32 1, i32 6, i32 7, i32 4, i32 5>
297283
; CHECK-NEXT: ret <8 x i16> [[SHUFFLE2]]
298284
;
299285
%shuffle1 = shufflevector <16 x i8> %v1, <16 x i8> undef, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>

0 commit comments

Comments
 (0)