Fix extraStack calculation -- I think in fact it might be getting a bit *too*
authorBrian Gaeke <gaeke@uiuc.edu>
Sun, 21 Nov 2004 03:35:22 +0000 (03:35 +0000)
committerBrian Gaeke <gaeke@uiuc.edu>
Sun, 21 Nov 2004 03:35:22 +0000 (03:35 +0000)
much stack, but that's better than not enough, which leads to miscompilations.

Fix FP vaarg.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18079 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Sparc/SparcV8ISelSimple.cpp
lib/Target/SparcV8/SparcV8ISelSimple.cpp

index 771657a34b775d55e6f838993bbf31aa202061cd..eab7dd658d26f7f6593c2fc7a1d2cc55e2e298d3 100644 (file)
@@ -834,9 +834,9 @@ void V8ISel::visitCallInst(CallInst &I) {
     }
   }
 
-  unsigned extraStack = 0;
   // How much extra call stack will we need?
-  for (unsigned i = 7; i < I.getNumOperands (); ++i) {
+  int extraStack = 0;
+  for (unsigned i = 0; i < I.getNumOperands (); ++i) {
     switch (getClassB (I.getOperand (i)->getType ())) {
       case cLong: extraStack += 8; break;
       case cFloat: extraStack += 4; break;
@@ -844,8 +844,13 @@ void V8ISel::visitCallInst(CallInst &I) {
       default: extraStack += 4; break;
     }
   }
-  // Round up extra stack size to the nearest doubleword.
-  if (extraStack) { extraStack = (extraStack + 7) & ~7; }
+  extraStack -= 24;
+  if (extraStack < 0) {
+    extraStack = 0;
+  } else {
+    // Round up extra stack size to the nearest doubleword.
+    extraStack = (extraStack + 7) & ~7;
+  }
 
   // Deal with args
   static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
@@ -1321,7 +1326,8 @@ void V8ISel::visitAllocaInst(AllocaInst &I) {
   unsigned TmpReg2 = makeAnotherReg (Type::UIntTy);
   unsigned StackAdjReg = makeAnotherReg (Type::UIntTy);
 
-  // StackAdjReg = (ArraySize * TySize) rounded up to nearest doubleword boundary
+  // StackAdjReg = (ArraySize * TySize) rounded up to nearest
+  // doubleword boundary.
   BuildMI (BB, V8::UMULrr, 2, TmpReg1).addReg (ArraySizeReg).addReg (TySizeReg);
 
   // Round up TmpReg1 to nearest doubleword boundary:
@@ -1417,11 +1423,18 @@ void V8ISel::visitVAArgInst (VAArgInst &I) {
        BuildMI (BB, V8::LD, 2, DestReg+1).addReg (VAList).addSImm (4);
     return;
 
-  case Type::FloatTyID:
-    BuildMI (BB, V8::LDFri, 2, DestReg).addReg (VAList).addSImm (0);
+  case Type::DoubleTyID: {
+    unsigned DblAlign = TM.getTargetData().getDoubleAlignment();
+    unsigned TempReg = makeAnotherReg (Type::IntTy);
+    unsigned TempReg2 = makeAnotherReg (Type::IntTy);
+    int FI = F->getFrameInfo()->CreateStackObject(8, DblAlign);
+    BuildMI (BB, V8::LD, 2, TempReg).addReg (VAList).addSImm (0);
+    BuildMI (BB, V8::LD, 2, TempReg2).addReg (VAList).addSImm (4);
+    BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (0).addReg (TempReg);
+    BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (4).addReg (TempReg2);
+    BuildMI (BB, V8::LDDFri, 2, DestReg).addFrameIndex (FI).addSImm (0);
     return;
-
-  case Type::DoubleTyID:
+  }
 
   default:
     std::cerr << "Sorry, vaarg instruction of this type still unsupported:\n"
index 771657a34b775d55e6f838993bbf31aa202061cd..eab7dd658d26f7f6593c2fc7a1d2cc55e2e298d3 100644 (file)
@@ -834,9 +834,9 @@ void V8ISel::visitCallInst(CallInst &I) {
     }
   }
 
-  unsigned extraStack = 0;
   // How much extra call stack will we need?
-  for (unsigned i = 7; i < I.getNumOperands (); ++i) {
+  int extraStack = 0;
+  for (unsigned i = 0; i < I.getNumOperands (); ++i) {
     switch (getClassB (I.getOperand (i)->getType ())) {
       case cLong: extraStack += 8; break;
       case cFloat: extraStack += 4; break;
@@ -844,8 +844,13 @@ void V8ISel::visitCallInst(CallInst &I) {
       default: extraStack += 4; break;
     }
   }
-  // Round up extra stack size to the nearest doubleword.
-  if (extraStack) { extraStack = (extraStack + 7) & ~7; }
+  extraStack -= 24;
+  if (extraStack < 0) {
+    extraStack = 0;
+  } else {
+    // Round up extra stack size to the nearest doubleword.
+    extraStack = (extraStack + 7) & ~7;
+  }
 
   // Deal with args
   static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
@@ -1321,7 +1326,8 @@ void V8ISel::visitAllocaInst(AllocaInst &I) {
   unsigned TmpReg2 = makeAnotherReg (Type::UIntTy);
   unsigned StackAdjReg = makeAnotherReg (Type::UIntTy);
 
-  // StackAdjReg = (ArraySize * TySize) rounded up to nearest doubleword boundary
+  // StackAdjReg = (ArraySize * TySize) rounded up to nearest
+  // doubleword boundary.
   BuildMI (BB, V8::UMULrr, 2, TmpReg1).addReg (ArraySizeReg).addReg (TySizeReg);
 
   // Round up TmpReg1 to nearest doubleword boundary:
@@ -1417,11 +1423,18 @@ void V8ISel::visitVAArgInst (VAArgInst &I) {
        BuildMI (BB, V8::LD, 2, DestReg+1).addReg (VAList).addSImm (4);
     return;
 
-  case Type::FloatTyID:
-    BuildMI (BB, V8::LDFri, 2, DestReg).addReg (VAList).addSImm (0);
+  case Type::DoubleTyID: {
+    unsigned DblAlign = TM.getTargetData().getDoubleAlignment();
+    unsigned TempReg = makeAnotherReg (Type::IntTy);
+    unsigned TempReg2 = makeAnotherReg (Type::IntTy);
+    int FI = F->getFrameInfo()->CreateStackObject(8, DblAlign);
+    BuildMI (BB, V8::LD, 2, TempReg).addReg (VAList).addSImm (0);
+    BuildMI (BB, V8::LD, 2, TempReg2).addReg (VAList).addSImm (4);
+    BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (0).addReg (TempReg);
+    BuildMI (BB, V8::ST, 3).addFrameIndex (FI).addSImm (4).addReg (TempReg2);
+    BuildMI (BB, V8::LDDFri, 2, DestReg).addFrameIndex (FI).addSImm (0);
     return;
-
-  case Type::DoubleTyID:
+  }
 
   default:
     std::cerr << "Sorry, vaarg instruction of this type still unsupported:\n"