[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
This commit is contained in:
Sam Parker 2020-06-11 14:52:17 +01:00
parent 0d4271f9da
commit 3d5f7c8531
2 changed files with 22 additions and 3 deletions

View File

@ -2053,8 +2053,8 @@ static bool isSingleSourceMaskImpl(ArrayRef<int> Mask, int NumOpElts) {
if (UsesLHS && UsesRHS)
return false;
}
assert((UsesLHS ^ UsesRHS) && "Should have selected from exactly 1 source");
return true;
// Allow for degenerate case: completely undef mask means neither source is used.
return UsesLHS || UsesRHS;
}
bool ShuffleVectorInst::isSingleSourceMask(ArrayRef<int> Mask) {
@ -2182,6 +2182,8 @@ bool ShuffleVectorInst::isExtractSubvectorMask(ArrayRef<int> Mask,
}
bool ShuffleVectorInst::isIdentityWithPadding() const {
if (isa<UndefValue>(Op<2>()))
return false;
int NumOpElts = cast<VectorType>(Op<0>()->getType())->getNumElements();
int NumMaskElts = cast<VectorType>(getType())->getNumElements();
if (NumMaskElts <= NumOpElts)
@ -2201,6 +2203,8 @@ bool ShuffleVectorInst::isIdentityWithPadding() const {
}
bool ShuffleVectorInst::isIdentityWithExtract() const {
if (isa<UndefValue>(Op<2>()))
return false;
int NumOpElts = cast<VectorType>(Op<0>()->getType())->getNumElements();
int NumMaskElts = getType()->getNumElements();
if (NumMaskElts >= NumOpElts)
@ -2211,7 +2215,8 @@ bool ShuffleVectorInst::isIdentityWithExtract() const {
bool ShuffleVectorInst::isConcat() const {
// Vector concatenation is differentiated from identity with padding.
if (isa<UndefValue>(Op<0>()) || isa<UndefValue>(Op<1>()))
if (isa<UndefValue>(Op<0>()) || isa<UndefValue>(Op<1>()) ||
isa<UndefValue>(Op<2>()))
return false;
int NumOpElts = cast<VectorType>(Op<0>()->getType())->getNumElements();

View File

@ -0,0 +1,14 @@
; RUN: opt -codegenprepare -S %s | FileCheck %s
target triple = "x86_64-unknown-linux-gnu"
; CHECK-LABEL: shuffle_one_source
define <2 x i8> @shuffle_one_source(i32 %x) {
%Shuf = shufflevector <2 x i8> zeroinitializer, <2 x i8> zeroinitializer, <2 x i32> undef
%Cmp = icmp slt i32 480483, %x
%B = mul <2 x i8> %Shuf, %Shuf
%S = select i1 %Cmp, <2 x i8> %B, <2 x i8> zeroinitializer
ret <2 x i8> %Shuf
}