Skip to content

Commit 3d5f7c8

Browse files
committed
[IR] Remove assert from ShuffleVectorInst
Which triggers on valid, but not useful, IR such as a undef mask. Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=46276 Differential Revision: https://reviews.llvm.org/D81634
1 parent 0d4271f commit 3d5f7c8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

llvm/lib/IR/Instructions.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,8 +2053,8 @@ static bool isSingleSourceMaskImpl(ArrayRef<int> Mask, int NumOpElts) {
20532053
if (UsesLHS && UsesRHS)
20542054
return false;
20552055
}
2056-
assert((UsesLHS ^ UsesRHS) && "Should have selected from exactly 1 source");
2057-
return true;
2056+
// Allow for degenerate case: completely undef mask means neither source is used.
2057+
return UsesLHS || UsesRHS;
20582058
}
20592059

20602060
bool ShuffleVectorInst::isSingleSourceMask(ArrayRef<int> Mask) {
@@ -2182,6 +2182,8 @@ bool ShuffleVectorInst::isExtractSubvectorMask(ArrayRef<int> Mask,
21822182
}
21832183

21842184
bool ShuffleVectorInst::isIdentityWithPadding() const {
2185+
if (isa<UndefValue>(Op<2>()))
2186+
return false;
21852187
int NumOpElts = cast<VectorType>(Op<0>()->getType())->getNumElements();
21862188
int NumMaskElts = cast<VectorType>(getType())->getNumElements();
21872189
if (NumMaskElts <= NumOpElts)
@@ -2201,6 +2203,8 @@ bool ShuffleVectorInst::isIdentityWithPadding() const {
22012203
}
22022204

22032205
bool ShuffleVectorInst::isIdentityWithExtract() const {
2206+
if (isa<UndefValue>(Op<2>()))
2207+
return false;
22042208
int NumOpElts = cast<VectorType>(Op<0>()->getType())->getNumElements();
22052209
int NumMaskElts = getType()->getNumElements();
22062210
if (NumMaskElts >= NumOpElts)
@@ -2211,7 +2215,8 @@ bool ShuffleVectorInst::isIdentityWithExtract() const {
22112215

22122216
bool ShuffleVectorInst::isConcat() const {
22132217
// Vector concatenation is differentiated from identity with padding.
2214-
if (isa<UndefValue>(Op<0>()) || isa<UndefValue>(Op<1>()))
2218+
if (isa<UndefValue>(Op<0>()) || isa<UndefValue>(Op<1>()) ||
2219+
isa<UndefValue>(Op<2>()))
22152220
return false;
22162221

22172222
int NumOpElts = cast<VectorType>(Op<0>()->getType())->getNumElements();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: opt -codegenprepare -S %s | FileCheck %s
2+
3+
target triple = "x86_64-unknown-linux-gnu"
4+
5+
; CHECK-LABEL: shuffle_one_source
6+
7+
define <2 x i8> @shuffle_one_source(i32 %x) {
8+
%Shuf = shufflevector <2 x i8> zeroinitializer, <2 x i8> zeroinitializer, <2 x i32> undef
9+
%Cmp = icmp slt i32 480483, %x
10+
%B = mul <2 x i8> %Shuf, %Shuf
11+
%S = select i1 %Cmp, <2 x i8> %B, <2 x i8> zeroinitializer
12+
ret <2 x i8> %Shuf
13+
}
14+

0 commit comments

Comments
 (0)