[llvm] 3d5f7c8 - [IR] Remove assert from ShuffleVectorInst

Sam Parker via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 11 06:52:47 PDT 2020


Author: Sam Parker
Date: 2020-06-11T14:52:17+01:00
New Revision: 3d5f7c853173938c6bb8052220487fd9d2987a77

URL: https://github.com/llvm/llvm-project/commit/3d5f7c853173938c6bb8052220487fd9d2987a77
DIFF: https://github.com/llvm/llvm-project/commit/3d5f7c853173938c6bb8052220487fd9d2987a77.diff

LOG: [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

Added: 
    llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll

Modified: 
    llvm/lib/IR/Instructions.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 3c7b79512908..22de967f1b5e 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -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 
diff erentiated 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();

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 000000000000..7433ff74bab5
--- /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
+}
+


        


More information about the llvm-commits mailing list