From 3d5f7c853173938c6bb8052220487fd9d2987a77 Mon Sep 17 00:00:00 2001 From: Sam Parker Date: Thu, 11 Jun 2020 14:52:17 +0100 Subject: [PATCH] [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 --- llvm/lib/IR/Instructions.cpp | 11 ++++++++--- .../Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 3c7b795..22de967 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -2053,8 +2053,8 @@ static bool isSingleSourceMaskImpl(ArrayRef 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 Mask) { @@ -2182,6 +2182,8 @@ bool ShuffleVectorInst::isExtractSubvectorMask(ArrayRef Mask, } bool ShuffleVectorInst::isIdentityWithPadding() const { + if (isa(Op<2>())) + return false; int NumOpElts = cast(Op<0>()->getType())->getNumElements(); int NumMaskElts = cast(getType())->getNumElements(); if (NumMaskElts <= NumOpElts) @@ -2201,6 +2203,8 @@ bool ShuffleVectorInst::isIdentityWithPadding() const { } bool ShuffleVectorInst::isIdentityWithExtract() const { + if (isa(Op<2>())) + return false; int NumOpElts = cast(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(Op<0>()) || isa(Op<1>())) + if (isa(Op<0>()) || isa(Op<1>()) || + isa(Op<2>())) return false; int NumOpElts = cast(Op<0>()->getType())->getNumElements(); diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll b/llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll new file mode 100644 index 0000000..7433ff7 --- /dev/null +++ b/llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll @@ -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 +} + -- 2.7.4