Skip to content

Commit 383fb91

Browse files
author
Adar Dagan
committed
Answer comments
1 parent 6fa9358 commit 383fb91

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,13 +708,13 @@ static Instruction *shrinkSplatShuffle(TruncInst &Trunc,
708708
auto *Shuf = dyn_cast<ShuffleVectorInst>(Trunc.getOperand(0));
709709
if (Shuf && Shuf->hasOneUse() && match(Shuf->getOperand(1), m_Undef()) &&
710710
all_equal(Shuf->getShuffleMask()) &&
711-
Shuf->getType()->getScalarType() ==
712-
Shuf->getOperand(0)->getType()->getScalarType()) {
711+
ElementCount::isKnownGE(Shuf->getType()->getElementCount(),
712+
cast<VectorType>(Shuf->getOperand(0)->getType())
713+
->getElementCount())) {
713714
// trunc (shuf X, Undef, SplatMask) --> shuf (trunc X), Poison, SplatMask
714715
// trunc (shuf X, Poison, SplatMask) --> shuf (trunc X), Poison, SplatMask
715-
auto *const NewTruncTy = VectorType::get(
716-
Trunc.getType()->getScalarType(),
717-
cast<VectorType>(Shuf->getOperand(0)->getType())->getElementCount());
716+
auto *const NewTruncTy = Shuf->getOperand(0)->getType()->getWithNewType(
717+
Trunc.getType()->getScalarType());
718718
Value *NarrowOp =
719719
Builder.CreateTrunc(Shuf->getOperand(0), NewTruncTy, Trunc.getName());
720720
return new ShuffleVectorInst(NarrowOp, Shuf->getShuffleMask(),

llvm/test/Transforms/InstCombine/trunc.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,17 @@ define <8 x i8> @wide_lengthening_splat(<4 x i16> %v) {
969969
ret <8 x i8> %tr
970970
}
971971

972+
define <4 x i8> @wide_shortening_splat(<8 x i16> %v) {
973+
; CHECK-LABEL: @wide_shortening_splat(
974+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <8 x i16> [[V:%.*]], <8 x i16> poison, <4 x i32> zeroinitializer
975+
; CHECK-NEXT: [[TR:%.*]] = trunc <4 x i16> [[SHUF]] to <4 x i8>
976+
; CHECK-NEXT: ret <4 x i8> [[TR]]
977+
;
978+
%shuf = shufflevector <8 x i16> %v, <8 x i16> %v, <4 x i32> zeroinitializer
979+
%tr = trunc <4 x i16> %shuf to <4 x i8>
980+
ret <4 x i8> %tr
981+
}
982+
972983
define <2 x i8> @narrow_add_vec_constant(<2 x i32> %x) {
973984
; CHECK-LABEL: @narrow_add_vec_constant(
974985
; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i32> [[X:%.*]] to <2 x i8>

0 commit comments

Comments
 (0)