Skip to content

Commit a8f1ed4

Browse files
authored
Merge pull request #5648 from apple/eng/PR-102150787-instcombine-assert
[InstCombine] Fix assert condition in `foldSelectShuffleOfSelectShuffle`
2 parents c38d16c + bee6b1d commit a8f1ed4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,10 @@ static Instruction *foldSelectShuffleOfSelectShuffle(ShuffleVectorInst &Shuf) {
20092009
for (unsigned i = 0; i != NumElts; ++i)
20102010
NewMask[i] = Mask[i] < (signed)NumElts ? Mask[i] : Mask1[i];
20112011

2012-
assert(ShuffleVectorInst::isSelectMask(NewMask) && "Unexpected shuffle mask");
2012+
// A select mask with undef elements might look like an identity mask.
2013+
assert((ShuffleVectorInst::isSelectMask(NewMask) ||
2014+
ShuffleVectorInst::isIdentityMask(NewMask)) &&
2015+
"Unexpected shuffle mask");
20132016
return new ShuffleVectorInst(X, Y, NewMask);
20142017
}
20152018

llvm/test/Transforms/InstCombine/shuffle_select.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,3 +1621,13 @@ define <4 x i32> @sel_common_op_extra_use(<4 x i32> %x, <4 x i32> %y) {
16211621
%s2 = shufflevector <4 x i32> %s1, <4 x i32> %x, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
16221622
ret <4 x i32> %s2
16231623
}
1624+
1625+
define <4 x float> @identity_mask(<4 x float>%x, <4 x float> %y) {
1626+
; CHECK-LABEL: @identity_mask(
1627+
; CHECK-NEXT: [[S2:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> poison, <4 x i32> <i32 0, i32 undef, i32 2, i32 3>
1628+
; CHECK-NEXT: ret <4 x float> [[S2]]
1629+
;
1630+
%s1 = shufflevector <4 x float> %x, <4 x float> %y, <4 x i32> <i32 0, i32 5, i32 undef, i32 undef>
1631+
%s2 = shufflevector <4 x float> %s1, <4 x float> %x, <4 x i32> <i32 0, i32 undef, i32 6, i32 7>
1632+
ret <4 x float> %s2
1633+
}

0 commit comments

Comments
 (0)