[llvm-commits] [llvm] r153864 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp test/CodeGen/X86/SwizzleShuff.ll
Nadav Rotem
nadav.rotem at intel.com
Mon Apr 2 00:11:13 PDT 2012
Author: nadav
Date: Mon Apr 2 02:11:12 2012
New Revision: 153864
URL: http://llvm.org/viewvc/llvm-project?rev=153864&view=rev
Log:
Optimizing swizzles of complex shuffles may generate additional complex shuffles.
Do not try to optimize swizzles of shuffles if the source shuffle has more than
a single user, except when the source shuffle is also a swizzle.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/SwizzleShuff.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=153864&r1=153863&r2=153864&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon Apr 2 02:11:12 2012
@@ -7792,6 +7792,14 @@
SmallVector<int, 8> NewMask;
ShuffleVectorSDNode *OtherSV = cast<ShuffleVectorSDNode>(N0);
+ // If the source shuffle has more than one user then do not try to optimize
+ // it because it may generate a more complex shuffle node. However, if the
+ // source shuffle is also a swizzle (a single source shuffle), our
+ // transformation is still likely to reduce the number of shuffles and only
+ // generate a simple shuffle node.
+ if (N0.getOperand(1).getOpcode() != ISD::UNDEF && !N0.hasOneUse())
+ return SDValue();
+
EVT InVT = N0.getValueType();
int InNumElts = InVT.getVectorNumElements();
@@ -7808,7 +7816,7 @@
NewMask.push_back(Idx);
}
-
+ assert(NewMask.size() == VT.getVectorNumElements() && "Invalid mask size");
return DAG.getVectorShuffle(VT, N->getDebugLoc(), OtherSV->getOperand(0),
OtherSV->getOperand(1), &NewMask[0]);
}
Modified: llvm/trunk/test/CodeGen/X86/SwizzleShuff.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/SwizzleShuff.ll?rev=153864&r1=153863&r2=153864&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/SwizzleShuff.ll (original)
+++ llvm/trunk/test/CodeGen/X86/SwizzleShuff.ll Mon Apr 2 02:11:12 2012
@@ -12,3 +12,20 @@
store <4 x i8> %C, <4 x i8>* %pA
ret void
}
+
+; CHECK: multi_use_swizzle
+; CHECK: mov
+; CHECK-NEXT: shuf
+; CHECK-NEXT: shuf
+; CHECK-NEXT: shuf
+; CHECK-NEXT: xor
+; CHECK-NEXT: ret
+define <4 x i32> @multi_use_swizzle (<4 x i32>* %pA, <4 x i32>* %pB) {
+ %A = load <4 x i32>* %pA
+ %B = load <4 x i32>* %pB
+ %S = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 1, i32 1, i32 5, i32 6>
+ %S1 = shufflevector <4 x i32> %S, <4 x i32> undef, <4 x i32> <i32 1, i32 3, i32 2, i32 2>
+ %S2 = shufflevector <4 x i32> %S, <4 x i32> undef, <4 x i32> <i32 2, i32 1, i32 0, i32 2>
+ %R = xor <4 x i32> %S1, %S2
+ ret <4 x i32> %R
+}
More information about the llvm-commits
mailing list