[PATCH] D32293: InstructionSimplify: Simplify a shuffle with a undef mask to undef

Zvi Rackover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 20 07:15:16 PDT 2017


zvi created this revision.

Following the discussion in pr32486, adding the simplification:
 shuffle %x, %y, undef -> undef


Repository:
  rL LLVM

https://reviews.llvm.org/D32293

Files:
  lib/Analysis/InstructionSimplify.cpp
  test/Transforms/InstSimplify/shufflevector.ll


Index: test/Transforms/InstSimplify/shufflevector.ll
===================================================================
--- test/Transforms/InstSimplify/shufflevector.ll
+++ test/Transforms/InstSimplify/shufflevector.ll
@@ -118,6 +118,14 @@
   ret <4 x i32> %shuf
 }
 
+define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
+; CHECK-LABEL: @undef_mask_1(
+; CHECK-NEXT:    ret <4 x i32> undef
+;
+  %shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> undef
+  ret <4 x i32> %shuf
+}
+
 define <4 x i32> @identity_mask_0(<4 x i32> %x) {
 ; CHECK-LABEL: @identity_mask_0(
 ; CHECK-NEXT:    ret <4 x i32> [[X:%.*]]
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -4144,6 +4144,9 @@
   auto *Op0Const = dyn_cast<Constant>(Op0);
   auto *Op1Const = dyn_cast<Constant>(Op1);
 
+  if (isa<UndefValue>(Mask))
+    return UndefValue::get(RetTy);
+
   // If all operands are constant, constant fold the shuffle.
   if (Op0Const && Op1Const)
     return ConstantFoldShuffleVectorInstruction(Op0Const, Op1Const, Mask);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32293.95955.patch
Type: text/x-patch
Size: 1172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170420/6e5d6115/attachment.bin>


More information about the llvm-commits mailing list