[llvm-commits] [llvm] r48058 - in /llvm/trunk: lib/CodeGen/SelectionDAG/SelectionDAG.cpp test/CodeGen/X86/vec_set-9.ll

Chris Lattner sabre at nondot.org
Sat Mar 8 15:43:37 PST 2008


Author: lattner
Date: Sat Mar  8 17:43:36 2008
New Revision: 48058

URL: http://llvm.org/viewvc/llvm-project?rev=48058&view=rev
Log:
Teach SD some vector identities, allowing us to compile vec_set-9 into:

_test3:
	movd	%rdi, %xmm1
	#IMPLICIT_DEF %xmm0
	punpcklqdq	%xmm1, %xmm0
	ret

instead of:

_test3:
	#IMPLICIT_DEF %rax
	movd	%rax, %xmm0
	movd	%rdi, %xmm1
	punpcklqdq	%xmm1, %xmm0
	ret

This is still not ideal.  There is no reason to two xmm regs.


Added:
    llvm/trunk/test/CodeGen/X86/vec_set-9.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=48058&r1=48057&r2=48058&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sat Mar  8 17:43:36 2008
@@ -1889,6 +1889,14 @@
     assert(MVT::isVector(VT) && !MVT::isVector(Operand.getValueType()) &&
            MVT::getVectorElementType(VT) == Operand.getValueType() &&
            "Illegal SCALAR_TO_VECTOR node!");
+    if (OpOpcode == ISD::UNDEF)
+      return getNode(ISD::UNDEF, VT);
+    // scalar_to_vector(extract_vector_elt V, 0) -> V, top bits are undefined.
+    if (OpOpcode == ISD::EXTRACT_VECTOR_ELT &&
+        isa<ConstantSDNode>(Operand.getOperand(1)) &&
+        Operand.getConstantOperandVal(1) == 0 &&
+        Operand.getOperand(0).getValueType() == VT)
+      return Operand.getOperand(0);
     break;
   case ISD::FNEG:
     if (OpOpcode == ISD::FSUB)   // -(X-Y) -> (Y-X)
@@ -2039,6 +2047,10 @@
   case ISD::EXTRACT_VECTOR_ELT:
     assert(N2C && "Bad EXTRACT_VECTOR_ELT!");
 
+    // EXTRACT_VECTOR_ELT of an UNDEF is an UNDEF.
+    if (N1.getOpcode() == ISD::UNDEF)
+      return getNode(ISD::UNDEF, VT);
+      
     // EXTRACT_VECTOR_ELT of CONCAT_VECTORS is often formed while lowering is
     // expanding copies of large vectors from registers.
     if (N1.getOpcode() == ISD::CONCAT_VECTORS &&
@@ -2054,7 +2066,7 @@
     // 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)

Added: llvm/trunk/test/CodeGen/X86/vec_set-9.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vec_set-9.ll?rev=48058&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/vec_set-9.ll (added)
+++ llvm/trunk/test/CodeGen/X86/vec_set-9.ll Sat Mar  8 17:43:36 2008
@@ -0,0 +1,8 @@
+; RUN: llvm-as < %s | llc -march=x86-64 | grep movd | count 1
+
+define <2 x i64> @test3(i64 %A) {
+entry:
+	%B = insertelement <2 x i64> undef, i64 %A, i32 1
+	ret <2 x i64> %B
+}
+





More information about the llvm-commits mailing list