[llvm-commits] [llvm] r64186 - in /llvm/trunk: lib/Target/X86/X86FloatingPoint.cpp lib/Target/X86/X86InstrFPStack.td lib/Target/X86/X86InstrInfo.cpp test/CodeGen/X86/fp-stack-set-st1.ll

Evan Cheng evan.cheng at apple.com
Mon Feb 9 15:32:07 PST 2009


Author: evancheng
Date: Mon Feb  9 17:32:07 2009
New Revision: 64186

URL: http://llvm.org/viewvc/llvm-project?rev=64186&view=rev
Log:
Implement FpSET_ST1_*.

Added:
    llvm/trunk/test/CodeGen/X86/fp-stack-set-st1.ll
Modified:
    llvm/trunk/lib/Target/X86/X86FloatingPoint.cpp
    llvm/trunk/lib/Target/X86/X86InstrFPStack.td
    llvm/trunk/lib/Target/X86/X86InstrInfo.cpp

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86FloatingPoint.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FloatingPoint.cpp Mon Feb  9 17:32:07 2009
@@ -982,7 +982,21 @@
   case X86::FpSET_ST0_32:
   case X86::FpSET_ST0_64:
   case X86::FpSET_ST0_80:
-    assert(StackTop == 1 && "Stack should have one element on it to return!");
+    assert((StackTop == 1 || StackTop == 2)
+           && "Stack should have one or two element on it to return!");
+    --StackTop;   // "Forget" we have something on the top of stack!
+    break;
+  case X86::FpSET_ST1_32:
+  case X86::FpSET_ST1_64:
+  case X86::FpSET_ST1_80:
+    // StackTop can be 1 if a FpSET_ST0_* was before this. Exchange them.
+    if (StackTop == 1) {
+      BuildMI(*MBB, I, TII->get(X86::XCH_F)).addReg(X86::ST1);
+      NumFXCH++;
+      StackTop = 0;
+      break;
+    }
+    assert(StackTop == 2 && "Stack should have two element on it to return!");
     --StackTop;   // "Forget" we have something on the top of stack!
     break;
   case X86::MOV_Fp3232:

Modified: llvm/trunk/lib/Target/X86/X86InstrFPStack.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrFPStack.td?rev=64186&r1=64185&r2=64186&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrFPStack.td (original)
+++ llvm/trunk/lib/Target/X86/X86InstrFPStack.td Mon Feb  9 17:32:07 2009
@@ -151,6 +151,12 @@
 def FpSET_ST0_80 : FpI_<(outs), (ins RFP80:$src), SpecialFP, []>; // ST(0) = FPR
 }
 
+let Defs = [ST1] in {
+def FpSET_ST1_32 : FpI_<(outs), (ins RFP32:$src), SpecialFP, []>; // ST(1) = FPR
+def FpSET_ST1_64 : FpI_<(outs), (ins RFP64:$src), SpecialFP, []>; // ST(1) = FPR
+def FpSET_ST1_80 : FpI_<(outs), (ins RFP80:$src), SpecialFP, []>; // ST(1) = FPR
+}
+
 // FpIf32, FpIf64 - Floating Point Psuedo Instruction template.
 // f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
 // f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Mon Feb  9 17:32:07 2009
@@ -1753,19 +1753,20 @@
 
   // Moving to ST(0) turns into FpSET_ST0_32 etc.
   if (DestRC == &X86::RSTRegClass) {
-    // Copying to ST(0).  FIXME: handle ST(1) also
-    if (DestReg != X86::ST0)
+    // Copying to ST(0) / ST(1).
+    if (DestReg != X86::ST0 && DestReg != X86::ST1)
       // Can only copy to TOS right now
       return false;
+    bool isST0 = DestReg == X86::ST0;
     unsigned Opc;
     if (SrcRC == &X86::RFP32RegClass)
-      Opc = X86::FpSET_ST0_32;
+      Opc = isST0 ? X86::FpSET_ST0_32 : X86::FpSET_ST1_32;
     else if (SrcRC == &X86::RFP64RegClass)
-      Opc = X86::FpSET_ST0_64;
+      Opc = isST0 ? X86::FpSET_ST0_64 : X86::FpSET_ST1_64;
     else {
       if (SrcRC != &X86::RFP80RegClass)
         return false;
-      Opc = X86::FpSET_ST0_80;
+      Opc = isST0 ? X86::FpSET_ST0_80 : X86::FpSET_ST1_80;
     }
     BuildMI(MBB, MI, get(Opc)).addReg(SrcReg);
     return true;

Added: llvm/trunk/test/CodeGen/X86/fp-stack-set-st1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fp-stack-set-st1.ll?rev=64186&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/fp-stack-set-st1.ll (added)
+++ llvm/trunk/test/CodeGen/X86/fp-stack-set-st1.ll Mon Feb  9 17:32:07 2009
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep fxch | count 2
+
+define i32 @main() nounwind {
+entry:
+	%asmtmp = tail call { double, double } asm sideeffect "fmul\09%st(1),%st\0A\09fst\09%st(1)\0A\09frndint\0A\09fxch  %st(1)\0A\09fsub\09%st(1),%st\0A\09f2xm1\0A\09", "={st},={st(1)},0,1,~{dirflag},~{fpsr},~{flags}"(double 0x4030FEFBD582097D, double 4.620000e+01) nounwind		; <{ double, double }> [#uses=0]
+	unreachable
+}





More information about the llvm-commits mailing list