[PATCH] D31527: InstSimplify: A shuffle of a splat is always the splat itself
Zvi Rackover via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 31 01:39:31 PDT 2017
zvi created this revision.
Fold:
shuffle (splat-shuffle), undef, M --> splat-shuffle
This is the counterpart of https://reviews.llvm.org/D31426 which was done in the DAGCombiner.
Repository:
rL LLVM
https://reviews.llvm.org/D31527
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
@@ -4,14 +4,23 @@
define <4 x i32> @splat_operand(<4 x i32> %x) {
; CHECK-LABEL: @splat_operand(
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
-; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
-; CHECK-NEXT: ret <4 x i32> [[SHUF]]
+; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
;
%splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
%shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
ret <4 x i32> %shuf
}
+define <4 x i32> @splat_operand1(<4 x i32> %x, <4 x i32> %y) {
+; CHECK-LABEL: @splat_operand1(
+; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> [[Y:%.*]], <4 x i32> zeroinitializer
+; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
+;
+ %splat = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> zeroinitializer
+ %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
+ ret <4 x i32> %shuf
+}
+
define <4 x i32> @undef_mask(<4 x i32> %x) {
; CHECK-LABEL: @undef_mask(
; CHECK-NEXT: ret <4 x i32> undef
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -4118,6 +4118,11 @@
if (Op0Const && Op1Const)
return ConstantFoldShuffleVectorInstruction(Op0Const, Op1Const, Mask);
+ // A shuffle of a splat is always the splat itself
+ if (auto Op0Shuf = dyn_cast<ShuffleVectorInst>(Op0))
+ if (isa<UndefValue>(Op1) && Op0Shuf->getMask()->getSplatValue())
+ return Op0;
+
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31527.93603.patch
Type: text/x-patch
Size: 1979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170331/492f7a0a/attachment.bin>
More information about the llvm-commits
mailing list