llvm.org GIT mirror llvm / 44b5e6d
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153864 91177308-0d34-0410-b5e6-96231b3b80d8 Nadav Rotem 8 years ago
2 changed file(s) with 26 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
77917791 SmallVector NewMask;
77927792 ShuffleVectorSDNode *OtherSV = cast(N0);
77937793
7794 // If the source shuffle has more than one user then do not try to optimize
7795 // it because it may generate a more complex shuffle node. However, if the
7796 // source shuffle is also a swizzle (a single source shuffle), our
7797 // transformation is still likely to reduce the number of shuffles and only
7798 // generate a simple shuffle node.
7799 if (N0.getOperand(1).getOpcode() != ISD::UNDEF && !N0.hasOneUse())
7800 return SDValue();
7801
77947802 EVT InVT = N0.getValueType();
77957803 int InNumElts = InVT.getVectorNumElements();
77967804
78077815
78087816 NewMask.push_back(Idx);
78097817 }
7810
7818 assert(NewMask.size() == VT.getVectorNumElements() && "Invalid mask size");
78117819 return DAG.getVectorShuffle(VT, N->getDebugLoc(), OtherSV->getOperand(0),
78127820 OtherSV->getOperand(1), &NewMask[0]);
78137821 }
1111 store <4 x i8> %C, <4 x i8>* %pA
1212 ret void
1313 }
14
15 ; CHECK: multi_use_swizzle
16 ; CHECK: mov
17 ; CHECK-NEXT: shuf
18 ; CHECK-NEXT: shuf
19 ; CHECK-NEXT: shuf
20 ; CHECK-NEXT: xor
21 ; CHECK-NEXT: ret
22 define <4 x i32> @multi_use_swizzle (<4 x i32>* %pA, <4 x i32>* %pB) {
23 %A = load <4 x i32>* %pA
24 %B = load <4 x i32>* %pB
25 %S = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32>
26 %S1 = shufflevector <4 x i32> %S, <4 x i32> undef, <4 x i32>
27 %S2 = shufflevector <4 x i32> %S, <4 x i32> undef, <4 x i32>
28 %R = xor <4 x i32> %S1, %S2
29 ret <4 x i32> %R
30 }