Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 48a60dc

Browse files
committed
[InstCombine] avoid crashing on shuffle shrinkage when input type is not same as result type
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297280 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a53106e commit 48a60dc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ static Instruction *shrinkSplatShuffle(TruncInst &Trunc,
470470
InstCombiner::BuilderTy &Builder) {
471471
auto *Shuf = dyn_cast<ShuffleVectorInst>(Trunc.getOperand(0));
472472
if (Shuf && Shuf->hasOneUse() && isa<UndefValue>(Shuf->getOperand(1)) &&
473-
Shuf->getMask()->getSplatValue()) {
473+
Shuf->getMask()->getSplatValue() &&
474+
Shuf->getType() == Shuf->getOperand(0)->getType()) {
474475
// trunc (shuf X, Undef, SplatMask) --> shuf (trunc X), Undef, SplatMask
475476
Constant *NarrowUndef = UndefValue::get(Trunc.getType());
476477
Value *NarrowOp = Builder.CreateTrunc(Shuf->getOperand(0), Trunc.getType());

test/Transforms/InstCombine/trunc.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,16 @@ define <3 x i31> @wide_splat3(<3 x i33> %x) {
520520
ret <3 x i31> %trunc
521521
}
522522

523+
; TODO: The shuffle extends the length of the input vector. Should we shrink this?
524+
525+
define <8 x i8> @wide_lengthening_splat(<4 x i16> %v) {
526+
; CHECK-LABEL: @wide_lengthening_splat(
527+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i16> %v, <4 x i16> undef, <8 x i32> zeroinitializer
528+
; CHECK-NEXT: [[TR:%.*]] = trunc <8 x i16> [[SHUF]] to <8 x i8>
529+
; CHECK-NEXT: ret <8 x i8> [[TR]]
530+
;
531+
%shuf = shufflevector <4 x i16> %v, <4 x i16> %v, <8 x i32> zeroinitializer
532+
%tr = trunc <8 x i16> %shuf to <8 x i8>
533+
ret <8 x i8> %tr
534+
}
535+

0 commit comments

Comments
 (0)