Skip to content

Commit 157b8f3

Browse files
committed
Add tests, remove comment
1 parent 8c27278 commit 157b8f3

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,10 +2487,8 @@ bool VectorCombine::foldShuffleOfCastops(Instruction &I) {
24872487
if (!match(&I, m_Shuffle(m_Value(V0), m_Value(V1), m_Mask(OldMask))))
24882488
return false;
24892489

2490-
// Check whether this is a unary shuffle.
2491-
// TODO: check if this can be extended to match undef or unused values,
2492-
// perhaps using ShuffleVectorInst::isSingleSource.
2493-
bool IsBinaryShuffle = !isa<PoisonValue>(V1);
2490+
// Check whether this is a binary shuffle.
2491+
bool IsBinaryShuffle = !isa<UndefValue>(V1);
24942492

24952493
auto *C0 = dyn_cast<CastInst>(V0);
24962494
auto *C1 = dyn_cast<CastInst>(V1);

llvm/test/Transforms/VectorCombine/X86/shuffle-of-casts.ll

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,71 @@ define <16 x i32> @concat_sext_zext_v8i16_v16i32(<8 x i16> %a0, <8 x i16> %a1) {
342342
%r = shufflevector <8 x i32> %x0, <8 x i32> %x1, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
343343
ret <16 x i32> %r
344344
}
345+
346+
; Unary shuffles
347+
348+
define <4 x i16> @unary_shuffle_zext_v8i8_v4i16(<8 x i8> %a0) {
349+
; CHECK-LABEL: define <4 x i16> @unary_shuffle_zext_v8i8_v4i16(
350+
; CHECK-SAME: <8 x i8> [[A0:%.*]]) #[[ATTR0]] {
351+
; CHECK-NEXT: [[VEC_SHUFFLE:%.*]] = shufflevector <8 x i8> [[A0]], <8 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
352+
; CHECK-NEXT: [[X1:%.*]] = zext <4 x i8> [[VEC_SHUFFLE]] to <4 x i16>
353+
; CHECK-NEXT: ret <4 x i16> [[X1]]
354+
;
355+
%x1 = zext <8 x i8> %a0 to <8 x i16>
356+
%vec.shuffle = shufflevector <8 x i16> %x1, <8 x i16> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
357+
ret <4 x i16> %vec.shuffle
358+
}
359+
360+
define <4 x i16> @unary_shuffle_sext_v8i8_v4i16(<8 x i8> %a0) {
361+
; CHECK-LABEL: define <4 x i16> @unary_shuffle_sext_v8i8_v4i16(
362+
; CHECK-SAME: <8 x i8> [[A0:%.*]]) #[[ATTR0]] {
363+
; CHECK-NEXT: [[VEC_SHUFFLE:%.*]] = shufflevector <8 x i8> [[A0]], <8 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
364+
; CHECK-NEXT: [[X1:%.*]] = sext <4 x i8> [[VEC_SHUFFLE]] to <4 x i16>
365+
; CHECK-NEXT: ret <4 x i16> [[X1]]
366+
;
367+
%x1 = sext <8 x i8> %a0 to <8 x i16>
368+
%vec.shuffle = shufflevector <8 x i16> %x1, <8 x i16> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
369+
ret <4 x i16> %vec.shuffle
370+
}
371+
372+
define <4 x i16> @unary_shuffle_sext_v8i8_v4i16_undef(<8 x i8> %a0) {
373+
; CHECK-LABEL: define <4 x i16> @unary_shuffle_sext_v8i8_v4i16_undef(
374+
; CHECK-SAME: <8 x i8> [[A0:%.*]]) #[[ATTR0]] {
375+
; CHECK-NEXT: [[VEC_SHUFFLE:%.*]] = shufflevector <8 x i8> [[A0]], <8 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
376+
; CHECK-NEXT: [[X1:%.*]] = sext <4 x i8> [[VEC_SHUFFLE]] to <4 x i16>
377+
; CHECK-NEXT: ret <4 x i16> [[X1]]
378+
;
379+
%x1 = sext <8 x i8> %a0 to <8 x i16>
380+
%vec.shuffle = shufflevector <8 x i16> %x1, <8 x i16> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
381+
ret <4 x i16> %vec.shuffle
382+
}
383+
384+
; negative - avoid loop with foldBitcastOfShuffle
385+
386+
define <2 x i32> @unary_shuffle_bitcast_v8i8_v2i32(<8 x i8> %a0) {
387+
; CHECK-LABEL: define <2 x i32> @unary_shuffle_bitcast_v8i8_v2i32(
388+
; CHECK-SAME: <8 x i8> [[A0:%.*]]) #[[ATTR0]] {
389+
; CHECK-NEXT: [[X1:%.*]] = bitcast <8 x i8> [[A0]] to <2 x i32>
390+
; CHECK-NEXT: [[VEC_SHUFFLE:%.*]] = shufflevector <2 x i32> [[X1]], <2 x i32> poison, <2 x i32> <i32 0, i32 1>
391+
; CHECK-NEXT: ret <2 x i32> [[VEC_SHUFFLE]]
392+
;
393+
%x1 = bitcast <8 x i8> %a0 to <2 x i32>
394+
%vec.shuffle = shufflevector <2 x i32> %x1, <2 x i32> poison, <2 x i32> <i32 0, i32 1>
395+
ret <2 x i32> %vec.shuffle
396+
}
397+
398+
; negative - multiuse
399+
400+
define <4 x i16> @unary_shuffle_sext_v8i8_v4i16_multiuse(<8 x i8> %a0, ptr %a1) {
401+
; CHECK-LABEL: define <4 x i16> @unary_shuffle_sext_v8i8_v4i16_multiuse(
402+
; CHECK-SAME: <8 x i8> [[A0:%.*]], ptr [[A1:%.*]]) #[[ATTR0]] {
403+
; CHECK-NEXT: [[X1:%.*]] = sext <8 x i8> [[A0]] to <8 x i16>
404+
; CHECK-NEXT: [[VEC_SHUFFLE:%.*]] = shufflevector <8 x i16> [[X1]], <8 x i16> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
405+
; CHECK-NEXT: store <8 x i16> [[X1]], ptr [[A1]], align 16
406+
; CHECK-NEXT: ret <4 x i16> [[VEC_SHUFFLE]]
407+
;
408+
%x1 = sext <8 x i8> %a0 to <8 x i16>
409+
%vec.shuffle = shufflevector <8 x i16> %x1, <8 x i16> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
410+
store <8 x i16> %x1, ptr %a1, align 16
411+
ret <4 x i16> %vec.shuffle
412+
}

0 commit comments

Comments
 (0)