[llvm-commits] [llvm] r40478 - in /llvm/trunk: lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/v4f32-immediate.ll

Dan Gohman djg at cray.com
Tue Jul 24 15:55:09 PDT 2007


Author: djg
Date: Tue Jul 24 17:55:08 2007
New Revision: 40478

URL: http://llvm.org/viewvc/llvm-project?rev=40478&view=rev
Log:
Use movaps to load a v4f32 build_vector of all-constant values into a
register instead of loading each element individually.

Added:
    llvm/trunk/test/CodeGen/X86/v4f32-immediate.ll
Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=40478&r1=40477&r2=40478&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue Jul 24 17:55:08 2007
@@ -2495,6 +2495,7 @@
   unsigned NumZero  = 0;
   unsigned NumNonZero = 0;
   unsigned NonZeros = 0;
+  unsigned NumNonZeroImms = 0;
   std::set<SDOperand> Values;
   for (unsigned i = 0; i < NumElems; ++i) {
     SDOperand Elt = Op.getOperand(i);
@@ -2505,6 +2506,9 @@
       else {
         NonZeros |= (1 << i);
         NumNonZero++;
+        if (Elt.getOpcode() == ISD::Constant ||
+            Elt.getOpcode() == ISD::ConstantFP)
+          NumNonZeroImms++;
       }
     }
   }
@@ -2548,6 +2552,11 @@
     }
   }
 
+  // A vector full of immediates; various special cases are already
+  // handled, so this is best done with a single constant-pool load.
+  if (NumNonZero == NumNonZeroImms)
+    return SDOperand();
+
   // Let legalizer expand 2-wide build_vectors.
   if (EVTBits == 64)
     return SDOperand();

Added: llvm/trunk/test/CodeGen/X86/v4f32-immediate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/v4f32-immediate.ll?rev=40478&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/v4f32-immediate.ll (added)
+++ llvm/trunk/test/CodeGen/X86/v4f32-immediate.ll Tue Jul 24 17:55:08 2007
@@ -0,0 +1,5 @@
+; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse | grep movaps
+
+define <4 x float> @foo() {
+  ret <4 x float> <float 3.223542354, float 2.3, float 1.2, float 0.1>
+}





More information about the llvm-commits mailing list