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

Commit

Permalink
[InstCombine] avoid crashing on shuffle shrinkage when input type is …
Browse files Browse the repository at this point in the history
…not same as result type

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297280 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rotateright committed Mar 8, 2017
1 parent a53106e commit 48a60dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Transforms/InstCombine/InstCombineCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ static Instruction *shrinkSplatShuffle(TruncInst &Trunc,
InstCombiner::BuilderTy &Builder) {
auto *Shuf = dyn_cast<ShuffleVectorInst>(Trunc.getOperand(0));
if (Shuf && Shuf->hasOneUse() && isa<UndefValue>(Shuf->getOperand(1)) &&
Shuf->getMask()->getSplatValue()) {
Shuf->getMask()->getSplatValue() &&
Shuf->getType() == Shuf->getOperand(0)->getType()) {
// trunc (shuf X, Undef, SplatMask) --> shuf (trunc X), Undef, SplatMask
Constant *NarrowUndef = UndefValue::get(Trunc.getType());
Value *NarrowOp = Builder.CreateTrunc(Shuf->getOperand(0), Trunc.getType());
Expand Down
13 changes: 13 additions & 0 deletions test/Transforms/InstCombine/trunc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,16 @@ define <3 x i31> @wide_splat3(<3 x i33> %x) {
ret <3 x i31> %trunc
}

; TODO: The shuffle extends the length of the input vector. Should we shrink this?

define <8 x i8> @wide_lengthening_splat(<4 x i16> %v) {
; CHECK-LABEL: @wide_lengthening_splat(
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i16> %v, <4 x i16> undef, <8 x i32> zeroinitializer
; CHECK-NEXT: [[TR:%.*]] = trunc <8 x i16> [[SHUF]] to <8 x i8>
; CHECK-NEXT: ret <8 x i8> [[TR]]
;
%shuf = shufflevector <4 x i16> %v, <4 x i16> %v, <8 x i32> zeroinitializer
%tr = trunc <8 x i16> %shuf to <8 x i8>
ret <8 x i8> %tr
}

0 comments on commit 48a60dc

Please sign in to comment.