[llvm-commits] [llvm] r38503 - in /llvm/trunk: lib/CodeGen/SelectionDAG/SelectionDAG.cpp test/CodeGen/X86/peep-vector-extract-concat.ll test/CodeGen/X86/peep-vector-extract-insert.ll
Dan Gohman
djg at cray.com
Tue Jul 10 11:20:44 PDT 2007
Author: djg
Date: Tue Jul 10 13:20:44 2007
New Revision: 38503
URL: http://llvm.org/viewvc/llvm-project?rev=38503&view=rev
Log:
Change the peep for EXTRACT_VECTOR_ELT of BUILD_PAIR to look for
the new CONCAT_VECTORS node type instead, as that's what legalize
uses now. And add a peep for EXTRACT_VECTOR_ELT of INSERT_VECTOR_ELT.
Added:
llvm/trunk/test/CodeGen/X86/peep-vector-extract-concat.ll
llvm/trunk/test/CodeGen/X86/peep-vector-extract-insert.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=38503&r1=38502&r2=38503&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Jul 10 13:20:44 2007
@@ -1968,19 +1968,31 @@
case ISD::EXTRACT_VECTOR_ELT:
assert(N2C && "Bad EXTRACT_VECTOR_ELT!");
- // EXTRACT_VECTOR_ELT of BUILD_PAIR is often formed while lowering is
+ // EXTRACT_VECTOR_ELT of CONCAT_VECTORS is often formed while lowering is
// expanding copies of large vectors from registers.
- if (N1.getOpcode() == ISD::BUILD_PAIR) {
- unsigned NewNumElts = MVT::getVectorNumElements(N1.getValueType()) / 2;
- bool Low = N2C->getValue() < NewNumElts;
- return getNode(ISD::EXTRACT_VECTOR_ELT, VT, N1.getOperand(!Low),
- Low ? N2 : getConstant(N2C->getValue() - NewNumElts,
- N2.getValueType()));
+ if (N1.getOpcode() == ISD::CONCAT_VECTORS &&
+ N1.getNumOperands() > 0) {
+ unsigned Factor =
+ MVT::getVectorNumElements(N1.getOperand(0).getValueType());
+ return getNode(ISD::EXTRACT_VECTOR_ELT, VT,
+ N1.getOperand(N2C->getValue() / Factor),
+ getConstant(N2C->getValue() % Factor, N2.getValueType()));
}
+
// EXTRACT_VECTOR_ELT of BUILD_VECTOR is often formed while lowering is
// expanding large vector constants.
if (N1.getOpcode() == ISD::BUILD_VECTOR)
return N1.getOperand(N2C->getValue());
+
+ // EXTRACT_VECTOR_ELT of INSERT_VECTOR_ELT is often formed when vector
+ // operations are lowered to scalars.
+ if (N1.getOpcode() == ISD::INSERT_VECTOR_ELT)
+ if (ConstantSDNode *IEC = dyn_cast<ConstantSDNode>(N1.getOperand(2))) {
+ if (IEC == N2C)
+ return N1.getOperand(1);
+ else
+ return getNode(ISD::EXTRACT_VECTOR_ELT, VT, N1.getOperand(0), N2);
+ }
break;
case ISD::EXTRACT_ELEMENT:
assert(N2C && (unsigned)N2C->getValue() < 2 && "Bad EXTRACT_ELEMENT!");
Added: llvm/trunk/test/CodeGen/X86/peep-vector-extract-concat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/peep-vector-extract-concat.ll?rev=38503&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/peep-vector-extract-concat.ll (added)
+++ llvm/trunk/test/CodeGen/X86/peep-vector-extract-concat.ll Tue Jul 10 13:20:44 2007
@@ -0,0 +1,6 @@
+; RUN: llvm-as < %s | llc -march=x86-64 | grep {shufps \$3, %xmm0, %xmm0}
+
+define float @foo(<8 x float> %a) {
+ %c = extractelement <8 x float> %a, i32 3
+ ret float %c
+}
Added: llvm/trunk/test/CodeGen/X86/peep-vector-extract-insert.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/peep-vector-extract-insert.ll?rev=38503&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/peep-vector-extract-insert.ll (added)
+++ llvm/trunk/test/CodeGen/X86/peep-vector-extract-insert.ll Tue Jul 10 13:20:44 2007
@@ -0,0 +1,12 @@
+; RUN: llvm-as < %s | llc -march=x86-64 | grep {pxor %xmm0, %xmm0} | wc -l | grep 2
+
+define float @foo(<4 x float> %a) {
+ %b = insertelement <4 x float> %a, float 0.0, i32 3
+ %c = extractelement <4 x float> %b, i32 3
+ ret float %c
+}
+define float @bar(float %a) {
+ %b = insertelement <4 x float> <float 3.4, float 4.5, float 0.0, float 9.2>, float %a, i32 3
+ %c = extractelement <4 x float> %b, i32 2
+ ret float %c
+}
More information about the llvm-commits
mailing list