[PATCH] D136256: [InstCombine] Fix assert condition in `foldSelectShuffleOfSelectShuffle`

Nabeel Omer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 08:07:24 PDT 2022


n-omer updated this revision to Diff 468917.
n-omer added a comment.

Address review comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136256/new/

https://reviews.llvm.org/D136256

Files:
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/test/Transforms/InstCombine/shuffle_select.ll


Index: llvm/test/Transforms/InstCombine/shuffle_select.ll
===================================================================
--- llvm/test/Transforms/InstCombine/shuffle_select.ll
+++ llvm/test/Transforms/InstCombine/shuffle_select.ll
@@ -1621,3 +1621,13 @@
   %s2 = shufflevector <4 x i32> %s1, <4 x i32> %x, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
   ret <4 x i32> %s2
 }
+
+define <4 x float> @identity_mask(<4 x float>%x, <4 x float> %y) {
+; CHECK-LABEL: @identity_mask(
+; CHECK-NEXT:    [[S2:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> poison, <4 x i32> <i32 0, i32 undef, i32 2, i32 3>
+; CHECK-NEXT:    ret <4 x float> [[S2]]
+;
+  %s1 = shufflevector <4 x float> %x, <4 x float> %y, <4 x i32> <i32 0, i32 5, i32 undef, i32 undef>
+  %s2 = shufflevector <4 x float> %s1, <4 x float> %x, <4 x i32> <i32 0, i32 undef, i32 6, i32 7>
+  ret <4 x float> %s2
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2004,7 +2004,10 @@
   for (unsigned i = 0; i != NumElts; ++i)
     NewMask[i] = Mask[i] < (signed)NumElts ? Mask[i] : Mask1[i];
 
-  assert(ShuffleVectorInst::isSelectMask(NewMask) && "Unexpected shuffle mask");
+  // A select mask with undef elements might look like an identity mask.
+  assert((ShuffleVectorInst::isSelectMask(NewMask) ||
+          ShuffleVectorInst::isIdentityMask(NewMask)) &&
+         "Unexpected shuffle mask");
   return new ShuffleVectorInst(X, Y, NewMask);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136256.468917.patch
Type: text/x-patch
Size: 1626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221019/dda38f28/attachment.bin>


More information about the llvm-commits mailing list