[llvm-commits] [llvm] r47660 - in /llvm/trunk: lib/Target/X86/README-X86-64.txt lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/x86-64-dead-stack-adjust.ll

Chris Lattner sabre at nondot.org
Tue Feb 26 21:57:41 PST 2008


Author: lattner
Date: Tue Feb 26 23:57:41 2008
New Revision: 47660

URL: http://llvm.org/viewvc/llvm-project?rev=47660&view=rev
Log:
Make X86TargetLowering::LowerSINT_TO_FP return without creating a dead 
stack slot and store if the  SINT_TO_FP is actually legal.  This allows
us to compile:

double a(double b) {return (unsigned)b;}

to:

_a:
	cvttsd2siq	%xmm0, %rax
	movl	%eax, %eax
	cvtsi2sdq	%rax, %xmm0
	ret

instead of:

_a:
	subq	$8, %rsp
	cvttsd2siq	%xmm0, %rax
	movl	%eax, %eax
	cvtsi2sdq	%rax, %xmm0
	addq	$8, %rsp
	ret

crazy.


Added:
    llvm/trunk/test/CodeGen/X86/x86-64-dead-stack-adjust.ll
Modified:
    llvm/trunk/lib/Target/X86/README-X86-64.txt
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Modified: llvm/trunk/lib/Target/X86/README-X86-64.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/README-X86-64.txt?rev=47660&r1=47659&r2=47660&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/README-X86-64.txt (original)
+++ llvm/trunk/lib/Target/X86/README-X86-64.txt Tue Feb 26 23:57:41 2008
@@ -236,18 +236,3 @@
 
 //===---------------------------------------------------------------------===//
 
-This function:
-double a(double b) {return (unsigned)b;} 
-compiles to this code:
-
-_a:
-	subq	$8, %rsp
-	cvttsd2siq	%xmm0, %rax
-	movl	%eax, %eax
-	cvtsi2sdq	%rax, %xmm0
-	addq	$8, %rsp
-	ret
-
-note the dead rsp adjustments.
-
-//===---------------------------------------------------------------------===//

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue Feb 26 23:57:41 2008
@@ -4148,12 +4148,17 @@
 }
 
 SDOperand X86TargetLowering::LowerSINT_TO_FP(SDOperand Op, SelectionDAG &DAG) {
-  assert(Op.getOperand(0).getValueType() <= MVT::i64 &&
-         Op.getOperand(0).getValueType() >= MVT::i16 &&
-         "Unknown SINT_TO_FP to lower!");
-
-  SDOperand Result;
   MVT::ValueType SrcVT = Op.getOperand(0).getValueType();
+  assert(SrcVT <= MVT::i64 && SrcVT >= MVT::i16 &&
+         "Unknown SINT_TO_FP to lower!");
+  
+  // These are really Legal; caller falls through into that case.
+  if (SrcVT == MVT::i32 && isScalarFPTypeInSSEReg(Op.getValueType()))
+    return SDOperand();
+  if (SrcVT == MVT::i64 && Op.getValueType() != MVT::f80 && 
+      Subtarget->is64Bit())
+    return SDOperand();
+  
   unsigned Size = MVT::getSizeInBits(SrcVT)/8;
   MachineFunction &MF = DAG.getMachineFunction();
   int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
@@ -4163,13 +4168,6 @@
                                  PseudoSourceValue::getFixedStack(),
                                  SSFI);
 
-  // These are really Legal; caller falls through into that case.
-  if (SrcVT == MVT::i32 && isScalarFPTypeInSSEReg(Op.getValueType()))
-    return Result;
-  if (SrcVT == MVT::i64 && Op.getValueType() != MVT::f80 && 
-      Subtarget->is64Bit())
-    return Result;
-
   // Build the FILD
   SDVTList Tys;
   bool useSSE = isScalarFPTypeInSSEReg(Op.getValueType());
@@ -4181,8 +4179,8 @@
   Ops.push_back(Chain);
   Ops.push_back(StackSlot);
   Ops.push_back(DAG.getValueType(SrcVT));
-  Result = DAG.getNode(useSSE ? X86ISD::FILD_FLAG :X86ISD::FILD,
-                       Tys, &Ops[0], Ops.size());
+  SDOperand Result = DAG.getNode(useSSE ? X86ISD::FILD_FLAG : X86ISD::FILD,
+                                 Tys, &Ops[0], Ops.size());
 
   if (useSSE) {
     Chain = Result.getValue(1);

Added: llvm/trunk/test/CodeGen/X86/x86-64-dead-stack-adjust.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-64-dead-stack-adjust.ll?rev=47660&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-64-dead-stack-adjust.ll (added)
+++ llvm/trunk/test/CodeGen/X86/x86-64-dead-stack-adjust.ll Tue Feb 26 23:57:41 2008
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | not grep rsp
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-apple-darwin8"
+
+define double @a(double %b) nounwind  {
+entry:
+	%tmp12 = fptoui double %b to i32		; <i32> [#uses=1]
+	%tmp123 = uitofp i32 %tmp12 to double		; <double> [#uses=1]
+	ret double %tmp123
+}





More information about the llvm-commits mailing list