llvm.org GIT mirror llvm / b2ed5fa
Optimize away nop CONCAT_VECTOR nodes. Optimize CONCAT_VECTOR nodes that merge EXTRACT_SUBVECTOR values that extract from the same vector. rdar://13402653 PR15866 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180871 91177308-0d34-0410-b5e6-96231b3b80d8 Nadav Rotem 7 years ago
2 changed file(s) with 52 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
91219121 if (ISD::allOperandsUndef(N))
91229122 return DAG.getUNDEF(N->getValueType(0));
91239123
9124 // Type legalization of vectors and DAG canonicalization of SHUFFLE_VECTOR
9125 // nodes often generate nop CONCAT_VECTOR nodes.
9126 // Scan the CONCAT_VECTOR operands and look for a CONCAT operations that
9127 // place the incoming vectors at the exact same location.
9128 SDValue SingleSource = SDValue();
9129 unsigned PartNumElem = N->getOperand(0).getValueType().getVectorNumElements();
9130
9131 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
9132 SDValue Op = N->getOperand(i);
9133
9134 if (Op.getOpcode() == ISD::UNDEF)
9135 continue;
9136
9137 // Check if this is the identity extract:
9138 if (Op.getOpcode() != ISD::EXTRACT_SUBVECTOR)
9139 return SDValue();
9140
9141 // Find the single incoming vector for the extract_subvector.
9142 if (SingleSource.getNode()) {
9143 if (Op.getOperand(0) != SingleSource)
9144 return SDValue();
9145 } else {
9146 SingleSource = Op.getOperand(0);
9147 }
9148
9149 unsigned IdentityIndex = i * PartNumElem;
9150 ConstantSDNode *CS = dyn_cast(Op.getOperand(1));
9151 // The extract index must be constant.
9152 if (!CS)
9153 return SDValue();
9154
9155 // Check that we are reading from the identity index.
9156 if (CS->getZExtValue() != IdentityIndex)
9157 return SDValue();
9158 }
9159
9160 if (SingleSource.getNode())
9161 return SingleSource;
9162
91249163 return SDValue();
91259164 }
91269165
0 ; RUN: llc < %s -mtriple=armv7-apple-darwin | FileCheck %s
1
2 ;CHECK: _foo
3 ;CHECK-NOT: vld1.32
4 ;CHECK-NOT: vst1.32
5 ;CHECK: bx
6 define void @foo(<16 x i8>* %J) {
7 %A = load <16 x i8>* %J
8 %T1 = shufflevector <16 x i8> %A, <16 x i8> undef, <8 x i32>
9 %T2 = shufflevector <8 x i8> %T1, <8 x i8> undef, <16 x i32>
10 store <16 x i8> %T2, <16 x i8>* %J
11 ret void
12 }