OSDN Git Service

(location_or_const_value_attribute, case CONCAT): Add.
[pf3gnuchains/gcc-fork.git] / gcc / reg-stack.c
index df45dd4..ea72b3a 100644 (file)
@@ -1,5 +1,5 @@
 /* Register to Stack convert for GNU compiler.
-   Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 /* This pass converts stack-like registers from the "flat register
    file" model that gcc uses, to a stack convention that the 387 uses.
@@ -164,14 +165,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "regs.h"
 #include "hard-reg-set.h"
 #include "flags.h"
+#include "insn-flags.h"
 
 #ifdef STACK_REGS
 
 #define REG_STACK_SIZE (LAST_STACK_REG - FIRST_STACK_REG + 1)
 
-/* True if the current function returns a real value. */
-static int current_function_returns_real;
-
 /* This is the basic stack record.  TOP is an index into REG[] such
    that REG[TOP] is the top of stack.  If TOP is -1 the stack is empty.
 
@@ -215,34 +214,107 @@ static HARD_REG_SET *block_out_reg_set;
    up by find_blocks and used there and in life_analysis.  It can be used
    later, but only to look up an insn that is the head or tail of some
    block.  life_analysis and the stack register conversion process can
-   add insns within a block. */
+   add insns within a block.  */
 static int *block_number;
 
 /* This is the register file for all register after conversion */
-static rtx FP_mode_reg[FIRST_PSEUDO_REGISTER][(int) MAX_MACHINE_MODE];
+static rtx
+  FP_mode_reg[LAST_STACK_REG+1-FIRST_STACK_REG][(int) MAX_MACHINE_MODE];
+
+#define FP_MODE_REG(regno,mode)        \
+  (FP_mode_reg[(regno)-FIRST_STACK_REG][(int)(mode)])
 
 /* Get the basic block number of an insn.  See note at block_number
-   definition are validity of this information. */
+   definition are validity of this information.  */
 
 #define BLOCK_NUM(INSN)  \
   ((INSN_UID (INSN) > max_uid) \
    ? (abort() , -1) : block_number[INSN_UID (INSN)])
 
 extern rtx forced_labels;
-extern rtx gen_jump ();
-extern rtx gen_movdf (), gen_movxf ();
-extern rtx find_regno_note ();
-extern rtx emit_jump_insn_before ();
-extern rtx emit_label_after ();
 
 /* Forward declarations */
 
-static void find_blocks ();
-static uses_reg_or_mem ();
-static void stack_reg_life_analysis ();
-static void change_stack ();
-static void convert_regs ();
-static void dump_stack_info ();
+static void mark_regs_pat              PROTO((rtx, HARD_REG_SET *));
+static void straighten_stack           PROTO((rtx, stack));
+static void record_label_references    PROTO((rtx, rtx));
+static rtx *get_true_reg               PROTO((rtx *));
+static int constrain_asm_operands      PROTO((int, rtx *, char **, int *,
+                                              enum reg_class *));
+
+static void record_asm_reg_life                PROTO((rtx,stack, rtx *, char **,
+                                              int, int));
+static void record_reg_life_pat                PROTO((rtx, HARD_REG_SET *,
+                                              HARD_REG_SET *, int));
+static void get_asm_operand_length     PROTO((rtx, int, int *, int *));
+static void record_reg_life            PROTO((rtx, int, stack));
+static void find_blocks                        PROTO((rtx));
+static int uses_reg_or_mem             PROTO((rtx));
+static rtx stack_result                        PROTO((tree));
+static void stack_reg_life_analysis    PROTO((rtx, HARD_REG_SET *));
+static void replace_reg                        PROTO((rtx *, int));
+static void remove_regno_note          PROTO((rtx, enum reg_note, int));
+static int get_hard_regnum             PROTO((stack, rtx));
+static void delete_insn_for_stacker    PROTO((rtx));
+static rtx emit_pop_insn               PROTO((rtx, stack, rtx, rtx (*) ()));
+static void emit_swap_insn             PROTO((rtx, stack, rtx));
+static void move_for_stack_reg         PROTO((rtx, stack, rtx));
+static void swap_rtx_condition         PROTO((rtx));
+static void compare_for_stack_reg      PROTO((rtx, stack, rtx));
+static void subst_stack_regs_pat       PROTO((rtx, stack, rtx));
+static void subst_asm_stack_regs       PROTO((rtx, stack, rtx *, rtx **,
+                                              char **, int, int));
+static void subst_stack_regs           PROTO((rtx, stack));
+static void change_stack               PROTO((rtx, stack, stack, rtx (*) ()));
+
+static void goto_block_pat             PROTO((rtx, stack, rtx));
+static void convert_regs               PROTO((void));
+static void print_blocks               PROTO((FILE *, rtx, rtx));
+static void dump_stack_info            PROTO((FILE *));
+\f
+/* Mark all registers needed for this pattern.  */
+
+static void
+mark_regs_pat (pat, set)
+     rtx pat;
+     HARD_REG_SET *set;
+{
+  enum machine_mode mode;
+  register int regno;
+  register int count;
+
+  if (GET_CODE (pat) == SUBREG)
+   {
+     mode = GET_MODE (pat);
+     regno = SUBREG_WORD (pat);
+     regno += REGNO (SUBREG_REG (pat));
+   }
+  else
+     regno = REGNO (pat), mode = GET_MODE (pat);
+
+  for (count = HARD_REGNO_NREGS (regno, mode);
+       count; count--, regno++)
+     SET_HARD_REG_BIT (*set, regno);
+}
+\f
+/* Reorganise the stack into ascending numbers,
+   after this insn.  */
+
+static void
+straighten_stack (insn, regstack)
+     rtx insn;
+     stack regstack;
+{
+  struct stack_def temp_stack;
+  int top;
+
+  temp_stack.reg_set = regstack->reg_set;
+
+  for (top = temp_stack.top = regstack->top; top >= 0; top--)
+     temp_stack.reg[top] = FIRST_STACK_REG + temp_stack.top - top;
+  
+  change_stack (insn, regstack, &temp_stack, emit_insn_after);
+}
 \f
 /* Return non-zero if any stack register is mentioned somewhere within PAT.  */
 
@@ -293,19 +365,37 @@ reg_to_stack (first, file)
   register int i;
   int stack_reg_seen = 0;
   enum machine_mode mode;
+  HARD_REG_SET stackentry;
 
-  current_function_returns_real
-    = TREE_CODE (TREE_TYPE (DECL_RESULT (current_function_decl))) == REAL_TYPE;
+  CLEAR_HARD_REG_SET (stackentry);
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
-    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
-      FP_mode_reg[i][(int) mode] = gen_rtx (REG, mode, i);
+   {
+     static initialised;
+     if (!initialised)
+      {
+#if 0
+       initialised = 1;        /* This array can not have been previously
+                                  initialised, because the rtx's are
+                                  thrown away between compilations of
+                                  functions.  */
+#endif
+        for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
+         {
+           for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
+               mode = GET_MODE_WIDER_MODE (mode))
+              FP_MODE_REG (i, mode) = gen_rtx (REG, mode, i);
+           for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_FLOAT); mode != VOIDmode;
+               mode = GET_MODE_WIDER_MODE (mode))
+              FP_MODE_REG (i, mode) = gen_rtx (REG, mode, i);
+         }
+      }
+   }
 
   /* Count the basic blocks.  Also find maximum insn uid.  */
   {
     register RTX_CODE prev_code = BARRIER;
     register RTX_CODE code;
+    register before_function_beg = 1;
 
     max_uid = 0;
     blocks = 0;
@@ -327,14 +417,24 @@ reg_to_stack (first, file)
                && GET_RTX_CLASS (code) == 'i'))
          blocks++;
 
+       if (code == NOTE && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
+          before_function_beg = 0;
+
        /* Remember whether or not this insn mentions an FP regs.
-          Check JUMP_INSNs too, in case someone creates a funny PARALLEL. */
+          Check JUMP_INSNs too, in case someone creates a funny PARALLEL.  */
 
-       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
+       if (GET_RTX_CLASS (code) == 'i'
            && stack_regs_mentioned_p (PATTERN (insn)))
          {
            stack_reg_seen = 1;
            PUT_MODE (insn, QImode);
+
+           /* Note any register passing parameters.  */
+
+           if (before_function_beg && code == INSN
+               && GET_CODE (PATTERN (insn)) == USE)
+              record_reg_life_pat (PATTERN (insn), (HARD_REG_SET *) 0,
+                                  &stackentry, 1);
          }
        else
          PUT_MODE (insn, VOIDmode);
@@ -353,13 +453,13 @@ reg_to_stack (first, file)
   if (! stack_reg_seen)
     return;
 
-  /* If there are stack registers, there must be at least one block. */
+  /* If there are stack registers, there must be at least one block.  */
 
   if (! blocks)
     abort ();
 
   /* Allocate some tables that last till end of compiling this function
-     and some needed only in find_blocks and life_analysis. */
+     and some needed only in find_blocks and life_analysis.  */
 
   block_begin = (rtx *) alloca (blocks * sizeof (rtx));
   block_end = (rtx *) alloca (blocks * sizeof (rtx));
@@ -373,11 +473,11 @@ reg_to_stack (first, file)
   block_number = (int *) alloca ((max_uid + 1) * sizeof (int));
 
   find_blocks (first);
-  stack_reg_life_analysis (first);
+  stack_reg_life_analysis (first, &stackentry);
 
   /* Dump the life analysis debug information before jump
      optimization, as that will destroy the LABEL_REFS we keep the
-     information in. */
+     information in.  */
 
   if (file)
     dump_stack_info (file);
@@ -390,7 +490,7 @@ reg_to_stack (first, file)
 \f
 /* Check PAT, which is in INSN, for LABEL_REFs.  Add INSN to the
    label's chain of references, and note which insn contains each
-   reference. */
+   reference.  */
 
 static void
 record_label_references (insn, pat)
@@ -408,7 +508,12 @@ record_label_references (insn, pat)
       if (GET_CODE (label) != CODE_LABEL)
        abort ();
 
-      /* Don't make a duplicate in the code_label's chain. */
+      /* If this is an undefined label, LABEL_REFS (label) contains
+         garbage.  */
+      if (INSN_UID (label) == 0)
+       return;
+
+      /* Don't make a duplicate in the code_label's chain.  */
 
       for (ref = LABEL_REFS (label);
           ref && ref != label;
@@ -439,19 +544,33 @@ record_label_references (insn, pat)
 \f
 /* Return a pointer to the REG expression within PAT.  If PAT is not a
    REG, possible enclosed by a conversion rtx, return the inner part of
-   PAT that stopped the search. */
+   PAT that stopped the search.  */
 
 static rtx *
 get_true_reg (pat)
      rtx *pat;
 {
-  while (GET_CODE (*pat) == SUBREG
-        || GET_CODE (*pat) == FLOAT
-        || GET_CODE (*pat) == FIX
-        || GET_CODE (*pat) == FLOAT_EXTEND)
-    pat = & XEXP (*pat, 0);
-
-  return pat;
+  for (;;)
+     switch (GET_CODE (*pat))
+      {
+       case SUBREG:
+               /* eliminate FP subregister accesses in favour of the
+                  actual FP register in use.  */
+        {
+          rtx subreg;
+          if (FP_REG_P (subreg = SUBREG_REG (*pat)))
+           {
+             *pat = FP_MODE_REG (REGNO (subreg) + SUBREG_WORD (*pat),
+                                 GET_MODE (subreg));
+       default:
+             return pat;
+           }
+        }
+       case FLOAT:
+       case FIX:
+       case FLOAT_EXTEND:
+          pat = & XEXP (*pat, 0);
+      }
 }
 \f
 /* Scan the OPERANDS and OPERAND_CONSTRAINTS of an asm_operands.
@@ -469,7 +588,7 @@ get_true_reg (pat)
    OPERAND_CLASS is set to `class' as required by the constraints, not to
    the subclass. If an alternative allows more than one class,
    OPERAND_CLASS is set to the smallest class that is a union of the
-   allowed classes. */
+   allowed classes.  */
 
 static int
 constrain_asm_operands (n_operands, operands, operand_constraints,
@@ -542,11 +661,11 @@ constrain_asm_operands (n_operands, operands, operand_constraints,
              case '!':
              case '*':
              case '%':
-               /* Ignore these. */
+               /* Ignore these.  */
                break;
 
              case '#':
-               /* Ignore rest of this alternative. */
+               /* Ignore rest of this alternative.  */
                while (*p && *p != ',') p++;
                break;
 
@@ -560,7 +679,7 @@ constrain_asm_operands (n_operands, operands, operand_constraints,
                   This kind of constraint is used for instructions such
                   as add when they take only two operands.
 
-                  Note that the lower-numbered operand is passed first. */
+                  Note that the lower-numbered operand is passed first.  */
 
                if (operands_match_p (operands[c - '0'],
                                      operands[this_operand]))
@@ -572,7 +691,7 @@ constrain_asm_operands (n_operands, operands, operand_constraints,
 
              case 'p':
                /* p is used for address_operands.  Since this is an asm,
-                  just to make sure that the operand is valid for Pmode. */
+                  just to make sure that the operand is valid for Pmode.  */
 
                if (strict_memory_address_p (Pmode, op))
                  win = 1;
@@ -605,7 +724,7 @@ constrain_asm_operands (n_operands, operands, operand_constraints,
 
              case 'X':
                /* This is used for a MATCH_SCRATCH in the cases when we
-                  don't actually need anything.  So anything goes any time. */
+                  don't actually need anything.  So anything goes any time.  */
                win = 1;
                break;
 
@@ -729,7 +848,7 @@ constrain_asm_operands (n_operands, operands, operand_constraints,
     }
 
   /* For operands constrained to match another operand, copy the other
-     operand's class to this operand's class. */
+     operand's class to this operand's class.  */
   for (j = 0; j < n_operands; j++)
     if (operand_matches[j] >= 0)
       operand_class[j] = operand_class[operand_matches[j]];
@@ -745,7 +864,7 @@ constrain_asm_operands (n_operands, operands, operand_constraints,
 
    There are many rules that an asm statement for stack-like regs must
    follow.  Those rules are explained at the top of this file: the rule
-   numbers below refer to that explanation. */
+   numbers below refer to that explanation.  */
 
 static void
 record_asm_reg_life (insn, regstack, operands, constraints,
@@ -780,7 +899,7 @@ record_asm_reg_life (insn, regstack, operands, constraints,
   if (i < 0)
     malformed_asm = 1;
 
-  /* Strip SUBREGs here to make the following code simpler. */
+  /* Strip SUBREGs here to make the following code simpler.  */
   for (i = 0; i < n_operands; i++)
     if (GET_CODE (operands[i]) == SUBREG
        && GET_CODE (SUBREG_REG (operands[i])) == REG)
@@ -816,7 +935,7 @@ record_asm_reg_life (insn, regstack, operands, constraints,
      operand constraints must select a class with a single reg.
 
      Also enforce rule #5: Output operands must start at the top of
-     the reg-stack: output operands may not "skip" a reg. */
+     the reg-stack: output operands may not "skip" a reg.  */
 
   bzero ((char *) reg_used_as_output, sizeof (reg_used_as_output));
   for (i = 0; i < n_outputs; i++)
@@ -849,14 +968,14 @@ record_asm_reg_life (insn, regstack, operands, constraints,
 
   /* Enforce rule #2: All implicitly popped input regs must be closer
      to the top of the reg-stack than any input that is not implicitly
-     popped. */
+     popped.  */
 
   bzero ((char *) implicitly_dies, sizeof (implicitly_dies));
   for (i = first_input; i < first_input + n_inputs; i++)
     if (STACK_REG_P (operands[i]))
       {
        /* An input reg is implicitly popped if it is tied to an
-          output, or if there is a CLOBBER for it. */
+          output, or if there is a CLOBBER for it.  */
        int j;
 
        for (j = 0; j < n_clobbers; j++)
@@ -888,7 +1007,7 @@ record_asm_reg_life (insn, regstack, operands, constraints,
      output constraints must use the "&" earlyclobber.
 
      ???  Detect this more deterministically by having constraint_asm_operands
-     record any earlyclobber. */
+     record any earlyclobber.  */
 
   for (i = first_input; i < first_input + n_inputs; i++)
     if (operand_matches[i] == -1)
@@ -961,36 +1080,38 @@ record_asm_reg_life (insn, regstack, operands, constraints,
    a SET_DEST in DEST, and other registers in SRC.
 
    This function does not know about SET_DESTs that are both input and
-   output (such as ZERO_EXTRACT) - this cannot happen on a 387. */
+   output (such as ZERO_EXTRACT) - this cannot happen on a 387.  */
 
-void
-record_reg_life_pat (pat, src, dest)
+static void
+record_reg_life_pat (pat, src, dest, douse)
      rtx pat;
      HARD_REG_SET *src, *dest;
+     int douse;
 {
   register char *fmt;
   register int i;
 
-  if (STACK_REG_P (pat))
+  if (STACK_REG_P (pat)
+      || (GET_CODE (pat) == SUBREG && STACK_REG_P (SUBREG_REG (pat))))
     {
       if (src)
-       SET_HARD_REG_BIT (*src, REGNO (pat));
+        mark_regs_pat (pat, src);
 
       if (dest)
-       SET_HARD_REG_BIT (*dest, REGNO (pat));
+        mark_regs_pat (pat, dest);
 
       return;
     }
 
   if (GET_CODE (pat) == SET)
     {
-      record_reg_life_pat (XEXP (pat, 0), NULL_PTR, dest);
-      record_reg_life_pat (XEXP (pat, 1), src, NULL_PTR);
+      record_reg_life_pat (XEXP (pat, 0), NULL_PTR, dest, 0);
+      record_reg_life_pat (XEXP (pat, 1), src, NULL_PTR, 0);
       return;
     }
 
-  /* We don't need to consider either of these cases. */
-  if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
+  /* We don't need to consider either of these cases.  */
+  if (GET_CODE (pat) == USE && !douse || GET_CODE (pat) == CLOBBER)
     return;
 
   fmt = GET_RTX_FORMAT (GET_CODE (pat));
@@ -1001,17 +1122,17 @@ record_reg_life_pat (pat, src, dest)
          register int j;
 
          for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
-           record_reg_life_pat (XVECEXP (pat, i, j), src, dest);
+           record_reg_life_pat (XVECEXP (pat, i, j), src, dest, 0);
        }
       else if (fmt[i] == 'e')
-       record_reg_life_pat (XEXP (pat, i), src, dest);
+       record_reg_life_pat (XEXP (pat, i), src, dest, 0);
     }
 }
 \f
 /* Calculate the number of inputs and outputs in BODY, an
    asm_operands.  N_OPERANDS is the total number of operands, and
    N_INPUTS and N_OUTPUTS are pointers to ints into which the results are
-   placed. */
+   placed.  */
 
 static void
 get_asm_operand_lengths (body, n_operands, n_inputs, n_outputs)
@@ -1048,7 +1169,7 @@ get_asm_operand_lengths (body, n_operands, n_inputs, n_outputs)
    register.  The block_end[] data is kept accurate.
 
    Existing death and unset notes for stack registers are deleted
-   before processing the insn. */
+   before processing the insn.  */
 
 static void
 record_reg_life (insn, block, regstack)
@@ -1074,13 +1195,13 @@ record_reg_life (insn, block, regstack)
     else
       note_link = &XEXP (note, 1);
 
-  /* Process all patterns in the insn. */
+  /* Process all patterns in the insn.  */
 
   n_operands = asm_noperands (PATTERN (insn));
   if (n_operands >= 0)
     {
       /* This insn is an `asm' with operands.  Decode the operands,
-        decide how many are inputs, and record the life information. */
+        decide how many are inputs, and record the life information.  */
 
       rtx operands[MAX_RECOG_OPERANDS];
       rtx body = PATTERN (insn);
@@ -1094,80 +1215,79 @@ record_reg_life (insn, block, regstack)
       return;
     }
 
-  /* An insn referencing a stack reg has a mode of QImode. */
-  if (GET_MODE (insn) == QImode)
     {
       HARD_REG_SET src, dest;
       int regno;
 
       CLEAR_HARD_REG_SET (src);
       CLEAR_HARD_REG_SET (dest);
-      record_reg_life_pat (PATTERN (insn), &src, &dest);
 
+      if (GET_CODE (insn) == CALL_INSN)
+        for (note = CALL_INSN_FUNCTION_USAGE (insn);
+             note;
+             note = XEXP (note, 1))
+          if (GET_CODE (XEXP (note, 0)) == USE)
+            record_reg_life_pat (SET_DEST (XEXP (note, 0)), &src, NULL_PTR, 0);
+
+      record_reg_life_pat (PATTERN (insn), &src, &dest, 0);
       for (regno = FIRST_STACK_REG; regno <= LAST_STACK_REG; regno++)
        if (! TEST_HARD_REG_BIT (regstack->reg_set, regno))
          {
            if (TEST_HARD_REG_BIT (src, regno)
                && ! TEST_HARD_REG_BIT (dest, regno))
              REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_DEAD,
-                                         FP_mode_reg[regno][(int) DFmode],
+                                         FP_MODE_REG (regno, DFmode),
                                          REG_NOTES (insn));
            else if (TEST_HARD_REG_BIT (dest, regno))
              REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_UNUSED,
-                                         FP_mode_reg[regno][(int) DFmode],
+                                         FP_MODE_REG (regno, DFmode),
                                          REG_NOTES (insn));
          }
 
-      AND_COMPL_HARD_REG_SET (regstack->reg_set, dest);
-      IOR_HARD_REG_SET (regstack->reg_set, src);
-    }
-
-  /* There might be a reg that is live after a function call.
-     Initialize it to zero so that the program does not crash.  See comment
-     towards the end of stack_reg_life_analysis(). */
-
-  if (GET_CODE (insn) == CALL_INSN)
-    {
-      int reg = FIRST_FLOAT_REG;
+      if (GET_CODE (insn) == CALL_INSN)
+        {
+         int reg;
 
-      /* If a stack reg is mentioned in a CALL_INSN, it must be as the
-        return value.  */
+          /* There might be a reg that is live after a function call.
+             Initialize it to zero so that the program does not crash.  See
+            comment towards the end of stack_reg_life_analysis().  */
 
-      if (stack_regs_mentioned_p (PATTERN (insn)))
-       reg++;
-
-      for (; reg <= LAST_STACK_REG; reg++)
-       if (TEST_HARD_REG_BIT (regstack->reg_set, reg))
-         {
-           rtx init, pat;
+          for (reg = FIRST_STACK_REG; reg <= LAST_STACK_REG; reg++)
+           if (! TEST_HARD_REG_BIT (dest, reg)
+               && TEST_HARD_REG_BIT (regstack->reg_set, reg))
+             {
+               rtx init, pat;
 
-           /* The insn will use virtual register numbers, and so
-              convert_regs is expected to process these.  But BLOCK_NUM
-              cannot be used on these insns, because they do not appear in
-              block_number[]. */
+               /* The insn will use virtual register numbers, and so
+                  convert_regs is expected to process these.  But BLOCK_NUM
+                  cannot be used on these insns, because they do not appear in
+                  block_number[].  */
 
-           pat = gen_rtx (SET, VOIDmode, FP_mode_reg[reg][(int) DFmode],
-                          CONST0_RTX (DFmode));
-           init = emit_insn_after (pat, insn);
-           PUT_MODE (init, QImode);
+               pat = gen_rtx (SET, VOIDmode, FP_MODE_REG (reg, DFmode),
+                              CONST0_RTX (DFmode));
+               init = emit_insn_after (pat, insn);
+               PUT_MODE (init, QImode);
 
-           CLEAR_HARD_REG_BIT (regstack->reg_set, reg);
+               CLEAR_HARD_REG_BIT (regstack->reg_set, reg);
 
-           /* If the CALL_INSN was the end of a block, move the
-              block_end to point to the new insn. */
+               /* If the CALL_INSN was the end of a block, move the
+                  block_end to point to the new insn.  */
 
-           if (block_end[block] == insn)
-             block_end[block] = init;
-         }
+               if (block_end[block] == insn)
+                 block_end[block] = init;
+             }
 
-      /* Some regs do not survive a CALL */
+         /* Some regs do not survive a CALL */
+          AND_COMPL_HARD_REG_SET (regstack->reg_set, call_used_reg_set);
+       }
 
-      AND_COMPL_HARD_REG_SET (regstack->reg_set, call_used_reg_set);
+      AND_COMPL_HARD_REG_SET (regstack->reg_set, dest);
+      IOR_HARD_REG_SET (regstack->reg_set, src);
     }
 }
 \f
 /* Find all basic blocks of the function, which starts with FIRST.
-   For each JUMP_INSN, build the chain of LABEL_REFS on each CODE_LABEL. */
+   For each JUMP_INSN, build the chain of LABEL_REFS on each CODE_LABEL.  */
 
 static void
 find_blocks (first)
@@ -1180,7 +1300,7 @@ find_blocks (first)
   rtx label_value_list = 0;
 
   /* Record where all the blocks start and end.
-     Record which basic blocks control can drop in to. */
+     Record which basic blocks control can drop in to.  */
 
   block = -1;
   for (insn = first; insn; insn = NEXT_INSN (insn))
@@ -1309,17 +1429,17 @@ uses_reg_or_mem (x)
 }
 
 /* If current function returns its result in an fp stack register,
-   return the register number.  Otherwise return -1.  */
+   return the REG.  Otherwise, return 0.  */
 
-static int
-stack_result_p (decl)
+static rtx
+stack_result (decl)
      tree decl;
 {
   rtx result = DECL_RTL (DECL_RESULT (decl));
 
   if (result != 0
-      && !(GET_CODE (result) == REG
-          && REGNO (result) < FIRST_PSEUDO_REGISTER))
+      && ! (GET_CODE (result) == REG
+           && REGNO (result) < FIRST_PSEUDO_REGISTER))
     {
 #ifdef FUNCTION_OUTGOING_VALUE
       result
@@ -1329,7 +1449,7 @@ stack_result_p (decl)
 #endif
     }
 
-  return STACK_REG_P (result) ? REGNO (result) : -1;
+  return result != 0 && STACK_REG_P (result) ? result : 0;
 }
 \f
 /* Determine the which registers are live at the start of each basic
@@ -1341,7 +1461,7 @@ stack_result_p (decl)
 
    Then, start with the last block and work back to the first block.
    Similarly, work backwards within each block, insn by insn, recording
-   which regs are die and which are used (and therefore live) in the
+   which regs are dead and which are used (and therefore live) in the
    hard reg set of block_stack_in[].
 
    After processing each basic block, if there is a label at the start
@@ -1360,34 +1480,36 @@ stack_result_p (decl)
 
    If there are registers that are live at the start of the function,
    insns are emitted to initialize these registers.  Something similar is
-   done after CALL_INSNs in record_reg_life. */
+   done after CALL_INSNs in record_reg_life.  */
 
 static void
-stack_reg_life_analysis (first)
+stack_reg_life_analysis (first, stackentry)
      rtx first;
+     HARD_REG_SET *stackentry;
 {
   int reg, block;
   struct stack_def regstack;
 
-  if (current_function_returns_real
-      && stack_result_p (current_function_decl) >= 0)
-    {
-      /* Find all RETURN insns and mark them. */
+   {
+     rtx retvalue;
 
-      int value_regno = stack_result_p (current_function_decl);
+     if (retvalue = stack_result (current_function_decl))
+      {
+        /* Find all RETURN insns and mark them.  */
 
-      for (block = blocks - 1; block >= 0; block--)
-       if (GET_CODE (block_end[block]) == JUMP_INSN
-           && GET_CODE (PATTERN (block_end[block])) == RETURN)
-         SET_HARD_REG_BIT (block_out_reg_set[block], value_regno);
+        for (block = blocks - 1; --block >= 0;)
+          if (GET_CODE (block_end[block]) == JUMP_INSN
+            && GET_CODE (PATTERN (block_end[block])) == RETURN)
+             mark_regs_pat (retvalue, block_out_reg_set+block);
 
-      /* Mark of the end of last block if we "fall off" the end of the
-        function into the epilogue. */
+        /* Mark off the end of last block if we "fall off" the end of the
+          function into the epilogue.  */
 
-      if (GET_CODE (block_end[blocks-1]) != JUMP_INSN
-         || GET_CODE (PATTERN (block_end[blocks-1])) == RETURN)
-       SET_HARD_REG_BIT (block_out_reg_set[blocks-1], value_regno);
-    }
+        if (GET_CODE (block_end[blocks-1]) != JUMP_INSN
+           || GET_CODE (PATTERN (block_end[blocks-1])) == RETURN)
+         mark_regs_pat (retvalue, block_out_reg_set+blocks-1);
+      }
+   }
 
   /* now scan all blocks backward for stack register use */
 
@@ -1408,7 +1530,7 @@ stack_reg_life_analysis (first)
 
          /* If the insn is a CALL_INSN, we need to ensure that
             everything dies.  But otherwise don't process unless there
-            are some stack regs present. */
+            are some stack regs present.  */
 
          if (GET_MODE (insn) == QImode || GET_CODE (insn) == CALL_INSN)
            record_reg_life (insn, block, &regstack);
@@ -1416,13 +1538,13 @@ stack_reg_life_analysis (first)
        } while (insn != block_begin[block]);
 
       /* Set the state at the start of the block.  Mark that no
-        register mapping information known yet. */
+        register mapping information known yet.  */
 
       COPY_HARD_REG_SET (block_stack_in[block].reg_set, regstack.reg_set);
       block_stack_in[block].top = -2;
 
       /* If there is a label, propagate our register life to all jumps
-        to this label. */
+        to this label.  */
 
       if (GET_CODE (insn) == CODE_LABEL)
        {
@@ -1443,7 +1565,7 @@ stack_reg_life_analysis (first)
                     processed.  If there are registers that were not known
                     to be live then, but are live now, we must back up
                     and restart life analysis from that point with the new
-                    life information. */
+                    life information.  */
 
                  GO_IF_HARD_REG_SUBSET (block_stack_in[block].reg_set,
                                         block_out_reg_set[jump_block],
@@ -1470,44 +1592,35 @@ stack_reg_life_analysis (first)
       block -= 1;
     }
 
-  {
     /* If any reg is live at the start of the first block of a
        function, then we must guarantee that the reg holds some value by
        generating our own "load" of that register.  Otherwise a 387 would
-       fault trying to access an empty register. */
-
-    HARD_REG_SET empty_regs;
-    CLEAR_HARD_REG_SET (empty_regs);
-    GO_IF_HARD_REG_SUBSET (block_stack_in[0].reg_set, empty_regs,
-                          no_live_regs);
-  }
+       fault trying to access an empty register.  */
 
   /* Load zero into each live register.  The fact that a register
-     appears live at the function start does not necessarily imply an error
-     in the user program: it merely means that we could not determine that
-     there wasn't such an error, just as -Wunused sometimes gives
-     "incorrect" warnings.  In those cases, these initializations will do
-     no harm.
+     appears live at the function start necessarily implies an error
+     in the user program: it means that (unless the offending code is *never*
+     executed) this program is using uninitialised floating point
+     variables.  In order to keep broken code like this happy, we initialise
+     those variables with zero.
 
      Note that we are inserting virtual register references here:
      these insns must be processed by convert_regs later.  Also, these
-     insns will not be in block_number, so BLOCK_NUM() will fail for them. */
+     insns will not be in block_number, so BLOCK_NUM() will fail for them.  */
 
   for (reg = LAST_STACK_REG; reg >= FIRST_STACK_REG; reg--)
-    if (TEST_HARD_REG_BIT (block_stack_in[0].reg_set, reg))
+    if (TEST_HARD_REG_BIT (block_stack_in[0].reg_set, reg)
+        && ! TEST_HARD_REG_BIT (*stackentry, reg))
       {
        rtx init_rtx;
 
-       init_rtx = gen_rtx (SET, VOIDmode, FP_mode_reg[reg][(int) DFmode],
+       init_rtx = gen_rtx (SET, VOIDmode, FP_MODE_REG(reg, DFmode),
                            CONST0_RTX (DFmode));
        block_begin[0] = emit_insn_after (init_rtx, first);
        PUT_MODE (block_begin[0], QImode);
 
        CLEAR_HARD_REG_BIT (block_stack_in[0].reg_set, reg);
       }
-
- no_live_regs:
-  ;
 }
 \f
 /*****************************************************************************
@@ -1516,7 +1629,7 @@ stack_reg_life_analysis (first)
  *****************************************************************************/
 
 /* Replace REG, which is a pointer to a stack reg RTX, with an RTX for
-   the desired hard REGNO. */
+   the desired hard REGNO.  */
 
 static void
 replace_reg (reg, regno)
@@ -1527,14 +1640,18 @@ replace_reg (reg, regno)
       || ! STACK_REG_P (*reg))
     abort ();
 
-  if (GET_MODE_CLASS (GET_MODE (*reg)) != MODE_FLOAT)
-    abort ();
+  switch (GET_MODE_CLASS (GET_MODE (*reg)))
+   {
+     default: abort ();
+     case MODE_FLOAT:
+     case MODE_COMPLEX_FLOAT:;
+   }
 
-  *reg = FP_mode_reg[regno][(int) GET_MODE (*reg)];
+  *reg = FP_MODE_REG (regno, GET_MODE (*reg));
 }
 
 /* Remove a note of type NOTE, which must be found, for register
-   number REGNO from INSN.  Remove only one such note. */
+   number REGNO from INSN.  Remove only one such note.  */
 
 static void
 remove_regno_note (insn, note, regno)
@@ -1560,7 +1677,7 @@ remove_regno_note (insn, note, regno)
 
 /* Find the hard register number of virtual register REG in REGSTACK.
    The hard register number is relative to the top of the stack.  -1 is
-   returned if the register is not found. */
+   returned if the register is not found.  */
 
 static int
 get_hard_regnum (regstack, reg)
@@ -1581,7 +1698,7 @@ get_hard_regnum (regstack, reg)
 
 /* Delete INSN from the RTL.  Mark the insn, but don't remove it from
    the chain of insns.  Doing so could confuse block_begin and block_end
-   if this were the only insn in the block. */
+   if this were the only insn in the block.  */
 
 static void
 delete_insn_for_stacker (insn)
@@ -1597,7 +1714,7 @@ delete_insn_for_stacker (insn)
    pop.  WHEN is either emit_insn_before or emit_insn_after.  A pop insn
    is represented as a SET whose destination is the register to be popped
    and source is the top of stack.  A death note for the top of stack
-   cases the movdf pattern to pop. */
+   cases the movdf pattern to pop.  */
 
 static rtx
 emit_pop_insn (insn, regstack, reg, when)
@@ -1614,15 +1731,15 @@ emit_pop_insn (insn, regstack, reg, when)
   if (hard_regno < FIRST_STACK_REG)
     abort ();
 
-  pop_rtx = gen_rtx (SET, VOIDmode, FP_mode_reg[hard_regno][(int) DFmode],
-                    FP_mode_reg[FIRST_STACK_REG][(int) DFmode]);
+  pop_rtx = gen_rtx (SET, VOIDmode, FP_MODE_REG (hard_regno, DFmode),
+                    FP_MODE_REG (FIRST_STACK_REG, DFmode));
 
   pop_insn = (*when) (pop_rtx, insn);
-  /* ??? This used to be VOIDmode, but that seems wrong. */
+  /* ??? This used to be VOIDmode, but that seems wrong.  */
   PUT_MODE (pop_insn, QImode);
 
   REG_NOTES (pop_insn) = gen_rtx (EXPR_LIST, REG_DEAD,
-                                 FP_mode_reg[FIRST_STACK_REG][(int) DFmode],
+                                 FP_MODE_REG (FIRST_STACK_REG, DFmode),
                                  REG_NOTES (pop_insn));
 
   regstack->reg[regstack->top - (hard_regno - FIRST_STACK_REG)]
@@ -1639,7 +1756,7 @@ emit_pop_insn (insn, regstack, reg, when)
    the swap.  A swap insn is represented as a PARALLEL of two patterns:
    each pattern moves one reg to the other.
 
-   If REG is already at the top of the stack, no insn is emitted. */
+   If REG is already at the top of the stack, no insn is emitted.  */
 
 static void
 emit_swap_insn (insn, regstack, reg)
@@ -1683,7 +1800,7 @@ emit_swap_insn (insn, regstack, reg)
       rtx i1dest = *get_true_reg (&SET_DEST (i1set));
 
       /* If the previous register stack push was from the reg we are to
-        swap with, omit the swap. */
+        swap with, omit the swap.  */
 
       if (GET_CODE (i1dest) == REG && REGNO (i1dest) == FIRST_STACK_REG
          && GET_CODE (i1src) == REG && REGNO (i1src) == hard_regno - 1
@@ -1706,15 +1823,15 @@ emit_swap_insn (insn, regstack, reg)
        abort ();
     }
 
-  swap_rtx = gen_swapdf (FP_mode_reg[hard_regno][(int) DFmode],
-                        FP_mode_reg[FIRST_STACK_REG][(int) DFmode]);
+  swap_rtx = gen_swapdf (FP_MODE_REG (hard_regno, DFmode),
+                        FP_MODE_REG (FIRST_STACK_REG, DFmode));
   swap_insn = emit_insn_after (swap_rtx, i1);
-  /* ??? This used to be VOIDmode, but that seems wrong. */
+  /* ??? This used to be VOIDmode, but that seems wrong.  */
   PUT_MODE (swap_insn, QImode);
 }
 \f
 /* Handle a move to or from a stack register in PAT, which is in INSN.
-   REGSTACK is the current stack. */
+   REGSTACK is the current stack.  */
 
 static void
 move_for_stack_reg (insn, regstack, pat)
@@ -1722,95 +1839,98 @@ move_for_stack_reg (insn, regstack, pat)
      stack regstack;
      rtx pat;
 {
-  rtx *src =  get_true_reg (&SET_SRC (pat));
-  rtx *dest = get_true_reg (&SET_DEST (pat));
+  rtx *psrc =  get_true_reg (&SET_SRC (pat));
+  rtx *pdest = get_true_reg (&SET_DEST (pat));
+  rtx src, dest;
   rtx note;
 
-  if (STACK_REG_P (*src) && STACK_REG_P (*dest))
+  src = *psrc; dest = *pdest;
+
+  if (STACK_REG_P (src) && STACK_REG_P (dest))
     {
       /* Write from one stack reg to another.  If SRC dies here, then
-        just change the register mapping and delete the insn. */
+        just change the register mapping and delete the insn.  */
 
-      note = find_regno_note (insn, REG_DEAD, REGNO (*src));
+      note = find_regno_note (insn, REG_DEAD, REGNO (src));
       if (note)
        {
          int i;
 
-         /* If this is a no-op move, there must not be a REG_DEAD note. */
-         if (REGNO (*src) == REGNO (*dest))
+         /* If this is a no-op move, there must not be a REG_DEAD note.  */
+         if (REGNO (src) == REGNO (dest))
            abort ();
 
          for (i = regstack->top; i >= 0; i--)
-           if (regstack->reg[i] == REGNO (*src))
+           if (regstack->reg[i] == REGNO (src))
              break;
 
-         /* The source must be live, and the dest must be dead. */
-         if (i < 0 || get_hard_regnum (regstack, *dest) >= FIRST_STACK_REG)
+         /* The source must be live, and the dest must be dead.  */
+         if (i < 0 || get_hard_regnum (regstack, dest) >= FIRST_STACK_REG)
            abort ();
 
          /* It is possible that the dest is unused after this insn.
-            If so, just pop the src. */
+            If so, just pop the src.  */
 
-         if (find_regno_note (insn, REG_UNUSED, REGNO (*dest)))
+         if (find_regno_note (insn, REG_UNUSED, REGNO (dest)))
            {
-             emit_pop_insn (insn, regstack, *src, emit_insn_after);
+             emit_pop_insn (insn, regstack, src, emit_insn_after);
 
              delete_insn_for_stacker (insn);
              return;
            }
 
-         regstack->reg[i] = REGNO (*dest);
+         regstack->reg[i] = REGNO (dest);
 
-         SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
-         CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (*src));
+         SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
+         CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (src));
 
          delete_insn_for_stacker (insn);
 
          return;
        }
 
-      /* The source reg does not die. */
+      /* The source reg does not die.  */
 
       /* If this appears to be a no-op move, delete it, or else it
         will confuse the machine description output patterns. But if
         it is REG_UNUSED, we must pop the reg now, as per-insn processing
-        for REG_UNUSED will not work for deleted insns. */
+        for REG_UNUSED will not work for deleted insns.  */
 
-      if (REGNO (*src) == REGNO (*dest))
+      if (REGNO (src) == REGNO (dest))
        {
-         if (find_regno_note (insn, REG_UNUSED, REGNO (*dest)))
-           emit_pop_insn (insn, regstack, *dest, emit_insn_after);
+         if (find_regno_note (insn, REG_UNUSED, REGNO (dest)))
+           emit_pop_insn (insn, regstack, dest, emit_insn_after);
 
          delete_insn_for_stacker (insn);
          return;
        }
 
       /* The destination ought to be dead */
-      if (get_hard_regnum (regstack, *dest) >= FIRST_STACK_REG)
+      if (get_hard_regnum (regstack, dest) >= FIRST_STACK_REG)
        abort ();
 
-      replace_reg (src, get_hard_regnum (regstack, *src));
+      replace_reg (psrc, get_hard_regnum (regstack, src));
 
-      regstack->reg[++regstack->top] = REGNO (*dest);
-      SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
-      replace_reg (dest, FIRST_STACK_REG);
+      regstack->reg[++regstack->top] = REGNO (dest);
+      SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
+      replace_reg (pdest, FIRST_STACK_REG);
     }
-  else if (STACK_REG_P (*src))
+  else if (STACK_REG_P (src))
     {
       /* Save from a stack reg to MEM, or possibly integer reg.  Since
         only top of stack may be saved, emit an exchange first if
-        needs be. */
+        needs be.  */
 
-      emit_swap_insn (insn, regstack, *src);
+      emit_swap_insn (insn, regstack, src);
 
-      note = find_regno_note (insn, REG_DEAD, REGNO (*src));
+      note = find_regno_note (insn, REG_DEAD, REGNO (src));
       if (note)
        {
          replace_reg (&XEXP (note, 0), FIRST_STACK_REG);
          regstack->top--;
-         CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (*src));
+         CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (src));
        }
-      else if (GET_MODE (*src) == XFmode && regstack->top != REG_STACK_SIZE)
+      else if (GET_MODE (src) == XFmode && regstack->top < REG_STACK_SIZE - 1)
        {
          /* A 387 cannot write an XFmode value to a MEM without
             clobbering the source reg.  The output code can handle
@@ -1820,7 +1940,7 @@ move_for_stack_reg (insn, regstack, pat)
             stack is not full, and then write the value to memory via
             a pop.  */
          rtx push_rtx, push_insn;
-         rtx top_stack_reg = FP_mode_reg[FIRST_STACK_REG][(int) XFmode];
+         rtx top_stack_reg = FP_MODE_REG (FIRST_STACK_REG, XFmode);
 
          push_rtx = gen_movxf (top_stack_reg, top_stack_reg);
          push_insn = emit_insn_before (push_rtx, insn);
@@ -1829,9 +1949,9 @@ move_for_stack_reg (insn, regstack, pat)
                                      REG_NOTES (insn));
        }
 
-      replace_reg (src, FIRST_STACK_REG);
+      replace_reg (psrc, FIRST_STACK_REG);
     }
-  else if (STACK_REG_P (*dest))
+  else if (STACK_REG_P (dest))
     {
       /* Load from MEM, or possibly integer REG or constant, into the
         stack regs.  The actual target is always the top of the
@@ -1839,21 +1959,21 @@ move_for_stack_reg (insn, regstack, pat)
         now at top of stack.  */
 
       /* The destination ought to be dead */
-      if (get_hard_regnum (regstack, *dest) >= FIRST_STACK_REG)
+      if (get_hard_regnum (regstack, dest) >= FIRST_STACK_REG)
        abort ();
 
       if (regstack->top >= REG_STACK_SIZE)
        abort ();
 
-      regstack->reg[++regstack->top] = REGNO (*dest);
-      SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
-      replace_reg (dest, FIRST_STACK_REG);
+      regstack->reg[++regstack->top] = REGNO (dest);
+      SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
+      replace_reg (pdest, FIRST_STACK_REG);
     }
   else
     abort ();
 }
 \f
-void
+static void
 swap_rtx_condition (pat)
      rtx pat;
 {
@@ -1887,7 +2007,7 @@ swap_rtx_condition (pat)
    Also, a pop insn may need to be emitted.  The 387 does have an
    `fcompp' insn that can pop two regs, but it is sometimes too expensive
    to do this - a `fcomp' followed by a `fstpl %st(0)' may be easier to
-   set up. */
+   set up.  */
 
 static void
 compare_for_stack_reg (insn, regstack, pat)
@@ -1897,12 +2017,29 @@ compare_for_stack_reg (insn, regstack, pat)
 {
   rtx *src1, *src2;
   rtx src1_note, src2_note;
+  rtx cc0_user;
 
   src1 = get_true_reg (&XEXP (SET_SRC (pat), 0));
   src2 = get_true_reg (&XEXP (SET_SRC (pat), 1));
+  cc0_user = next_cc0_user (insn);
+
+  /* If the insn that uses cc0 is a conditional move, then the destination
+     must be the top of stack */
+  if (GET_CODE (PATTERN (cc0_user)) == SET
+      && SET_DEST (PATTERN (cc0_user)) != pc_rtx
+      && GET_CODE (SET_SRC (PATTERN (cc0_user))) == IF_THEN_ELSE)
+    {
+      rtx *dest, src_note;
+      
+      dest = get_true_reg (&SET_DEST (PATTERN (cc0_user)));
+      if (REGNO (*dest) != regstack->reg[regstack->top])
+       {
+         emit_swap_insn (insn, regstack, *dest);       
+       }
+    }
 
   /* ??? If fxch turns out to be cheaper than fstp, give priority to
-     registers that die in this insn - move those to stack top first. */
+     registers that die in this insn - move those to stack top first.  */
   if (! STACK_REG_P (*src1)
       || (STACK_REG_P (*src2)
          && get_hard_regnum (regstack, *src2) == FIRST_STACK_REG))
@@ -1925,7 +2062,7 @@ compare_for_stack_reg (insn, regstack, pat)
       INSN_CODE (insn) = -1;
     }
 
-  /* We will fix any death note later. */
+  /* We will fix any death note later.  */
 
   src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
 
@@ -1950,7 +2087,7 @@ compare_for_stack_reg (insn, regstack, pat)
 
   /* If the second operand dies, handle that.  But if the operands are
      the same stack register, don't bother, because only one death is
-     needed, and it was just handled. */
+     needed, and it was just handled.  */
 
   if (src2_note
       && ! (STACK_REG_P (*src1) && STACK_REG_P (*src2)
@@ -1959,7 +2096,7 @@ compare_for_stack_reg (insn, regstack, pat)
       /* As a special case, two regs may die in this insn if src2 is
         next to top of stack and the top of stack also dies.  Since
         we have already popped src1, "next to top of stack" is really
-        at top (FIRST_STACK_REG) now. */
+        at top (FIRST_STACK_REG) now.  */
 
       if (get_hard_regnum (regstack, XEXP (src2_note, 0)) == FIRST_STACK_REG
          && src1_note)
@@ -1972,7 +2109,7 @@ compare_for_stack_reg (insn, regstack, pat)
        {
          /* The 386 can only represent death of the first operand in
             the case handled above.  In all other cases, emit a separate
-            pop and remove the death note from here. */
+            pop and remove the death note from here.  */
 
          link_cc0_insns (insn);
 
@@ -1985,7 +2122,7 @@ compare_for_stack_reg (insn, regstack, pat)
 }
 \f
 /* Substitute new registers in PAT, which is part of INSN.  REGSTACK
-   is the current register layout. */
+   is the current register layout.  */
 
 static void
 subst_stack_regs_pat (insn, regstack, pat)
@@ -2003,7 +2140,7 @@ subst_stack_regs_pat (insn, regstack, pat)
   dest = get_true_reg (&SET_DEST (pat));
   src  = get_true_reg (&SET_SRC (pat));
 
-  /* See if this is a `movM' pattern, and handle elsewhere if so. */
+  /* See if this is a `movM' pattern, and handle elsewhere if so.  */
 
   if (*dest != cc0_rtx
       && (STACK_REG_P (*src)
@@ -2019,19 +2156,26 @@ subst_stack_regs_pat (insn, regstack, pat)
        break;
 
       case CALL:
-       regstack->reg[++regstack->top] = REGNO (*dest);
-       SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
+        {
+          int count;
+          for (count = HARD_REGNO_NREGS (REGNO (*dest), GET_MODE (*dest));
+              --count >= 0;)
+           {
+             regstack->reg[++regstack->top] = REGNO (*dest) + count;
+             SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest) + count);
+           }
+        }
        replace_reg (dest, FIRST_STACK_REG);
        break;
 
       case REG:
-       /* This is a `tstM2' case. */
+       /* This is a `tstM2' case.  */
        if (*dest != cc0_rtx)
          abort ();
 
        src1 = src;
 
-       /* Fall through. */
+       /* Fall through.  */
 
       case FLOAT_TRUNCATE:
       case SQRT:
@@ -2067,18 +2211,18 @@ subst_stack_regs_pat (insn, regstack, pat)
       case DIV:
        /* On i386, reversed forms of subM3 and divM3 exist for
           MODE_FLOAT, so the same code that works for addM3 and mulM3
-          can be used. */
+          can be used.  */
       case MULT:
       case PLUS:
        /* These insns can accept the top of stack as a destination
           from a stack reg or mem, or can use the top of stack as a
           source and some other stack register (possibly top of stack)
-          as a destination. */
+          as a destination.  */
 
        src1 = get_true_reg (&XEXP (SET_SRC (pat), 0));
        src2 = get_true_reg (&XEXP (SET_SRC (pat), 1));
 
-       /* We will fix any death note later. */
+       /* We will fix any death note later.  */
 
        if (STACK_REG_P (*src1))
          src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
@@ -2090,7 +2234,7 @@ subst_stack_regs_pat (insn, regstack, pat)
          src2_note = NULL_RTX;
 
        /* If either operand is not a stack register, then the dest
-          must be top of stack. */
+          must be top of stack.  */
 
        if (! STACK_REG_P (*src1) || ! STACK_REG_P (*src2))
          emit_swap_insn (insn, regstack, *dest);
@@ -2123,7 +2267,7 @@ subst_stack_regs_pat (insn, regstack, pat)
               the destination is somewhere else - merely substitute it.
               But if the reg that dies is not at top of stack, then
               move the top of stack to the dead reg, as though we had
-              done the insn and then a store-with-pop. */
+              done the insn and then a store-with-pop.  */
 
            if (REGNO (XEXP (src1_note, 0)) == regstack->reg[regstack->top])
              {
@@ -2209,6 +2353,55 @@ subst_stack_regs_pat (insn, regstack, pat)
          }
        break;
 
+      case IF_THEN_ELSE:
+       /* This insn requires the top of stack to be the destination. */
+
+       src1 = get_true_reg (&XEXP (SET_SRC (pat), 1));
+       src2 = get_true_reg (&XEXP (SET_SRC (pat), 2));
+
+       src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
+       src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
+
+       {
+         rtx src_note [] = {0, src1_note, src2_note};
+         int i;
+
+         if (STACK_REG_P (*src1))
+           replace_reg (src1, get_hard_regnum (regstack, *src1));
+         if (STACK_REG_P (*src2))
+           replace_reg (src2, get_hard_regnum (regstack, *src2));
+
+         for (i = 1; i <= 2; i++)
+           if (src_note [i])
+             {
+               int regno = get_hard_regnum (regstack, XEXP (src_note [i], 0));
+
+               /* If the register that dies is not at the top of stack, then
+                  move the top of stack to the dead reg */
+               if (REGNO (XEXP (src_note[i], 0))
+                   != regstack->reg[regstack->top])
+                 {
+                   remove_regno_note (insn, REG_DEAD,
+                                      REGNO (XEXP (src_note [i], 0)));
+                   emit_pop_insn (insn, regstack, XEXP (src_note[i], 0),
+                                  emit_insn_after);
+                 }
+               else
+                 {
+                   CLEAR_HARD_REG_BIT (regstack->reg_set,
+                                       REGNO (XEXP (src_note[i], 0)));
+                   replace_reg (&XEXP (src_note[i], 0), FIRST_STACK_REG);
+                   regstack->top--;
+                 }
+               
+             }
+
+         SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
+         replace_reg (dest, FIRST_STACK_REG);
+       }
+
+       break;
+
       default:
        abort ();
       }
@@ -2262,14 +2455,14 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
   /* Find out what the constraints required.  If no constraint
      alternative matches, that is a compiler bug: we should have caught
      such an insn during the life analysis pass (and reload should have
-     caught it regardless). */
+     caught it regardless).  */
 
   i = constrain_asm_operands (n_operands, operands, constraints,
                              operand_matches, operand_class);
   if (i < 0)
     abort ();
 
-  /* Strip SUBREGs here to make the following code simpler. */
+  /* Strip SUBREGs here to make the following code simpler.  */
   for (i = 0; i < n_operands; i++)
     if (GET_CODE (operands[i]) == SUBREG
        && GET_CODE (SUBREG_REG (operands[i])) == REG)
@@ -2355,7 +2548,7 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
           these constraints are for single register classes, and reload
           guaranteed that operand[i] is already in that class, we can
           just use REGNO (operands[i]) to know which actual reg this
-          operand needs to be in. */
+          operand needs to be in.  */
 
        int regno = get_hard_regnum (&temp_stack, operands[i]);
 
@@ -2367,7 +2560,7 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
            /* operands[i] is not in the right place.  Find it
               and swap it with whatever is already in I's place.
               K is where operands[i] is now.  J is where it should
-              be. */
+              be.  */
            int j, k, temp;
 
            k = temp_stack.top - (regno - FIRST_STACK_REG);
@@ -2386,7 +2579,7 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
   change_stack (insn, regstack, &temp_stack, emit_insn_before);
 
   /* Make the needed input register substitutions.  Do death notes and
-     clobbers too, because these are for inputs, not outputs. */
+     clobbers too, because these are for inputs, not outputs.  */
 
   for (i = first_input; i < first_input + n_inputs; i++)
     if (STACK_REG_P (operands[i]))
@@ -2422,17 +2615,17 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
             that these regs can't be MODE_INT and will abort.  Just put
             the right reg there without calling replace_reg.  */
 
-         *clobber_loc[i] = FP_mode_reg[regnum][(int) DFmode];
+         *clobber_loc[i] = FP_MODE_REG (regnum, DFmode);
        }
     }
 
-  /* Now remove from REGSTACK any inputs that the asm implicitly popped. */
+  /* Now remove from REGSTACK any inputs that the asm implicitly popped.  */
 
   for (i = first_input; i < first_input + n_inputs; i++)
     if (STACK_REG_P (operands[i]))
       {
        /* An input reg is implicitly popped if it is tied to an
-          output, or if there is a CLOBBER for it. */
+          output, or if there is a CLOBBER for it.  */
        int j;
 
        for (j = 0; j < n_clobbers; j++)
@@ -2455,7 +2648,7 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
 
   /* Now add to REGSTACK any outputs that the asm implicitly pushed.
      Note that there isn't any need to substitute register numbers.
-     ???  Explain why this is true. */
+     ???  Explain why this is true.  */
 
   for (i = LAST_STACK_REG; i >= FIRST_STACK_REG; i--)
     {
@@ -2513,7 +2706,7 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
 /* Substitute stack hard reg numbers for stack virtual registers in
    INSN.  Non-stack register numbers are not changed.  REGSTACK is the
    current stack content.  Insns may be emitted as needed to arrange the
-   stack for the 387 based on the contents of the insn. */
+   stack for the 387 based on the contents of the insn.  */
 
 static void
 subst_stack_regs (insn, regstack)
@@ -2524,22 +2717,33 @@ subst_stack_regs (insn, regstack)
   register int i;
   int n_operands;
 
-  if ((GET_CODE (insn) != INSN && GET_CODE (insn) != CALL_INSN)
-      || INSN_DELETED_P (insn))
-    return;
+  if (GET_CODE (insn) == CALL_INSN)
+   {
+     int top = regstack->top;
 
-  /* The stack should be empty at a call. */
+     /* If there are any floating point parameters to be passed in
+       registers for this call, make sure they are in the right
+       order.  */
 
-  if (GET_CODE (insn) == CALL_INSN)
-    for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
-      if (TEST_HARD_REG_BIT (regstack->reg_set, i))
-       abort ();
+     if (top >= 0)
+      {
+       straighten_stack (PREV_INSN (insn), regstack);
+
+       /* Now mark the arguments as dead after the call.  */
+
+        while (regstack->top >= 0)
+         {
+           CLEAR_HARD_REG_BIT (regstack->reg_set, FIRST_STACK_REG + regstack->top);
+          regstack->top--;
+         }
+      }
+   }
 
   /* Do the actual substitution if any stack regs are mentioned.
      Since we only record whether entire insn mentions stack regs, and
      subst_stack_regs_pat only works for patterns that contain stack regs,
      we must check each pattern in a parallel here.  A call_value_pop could
-     fail otherwise. */
+     fail otherwise.  */
 
   if (GET_MODE (insn) == QImode)
     {
@@ -2548,7 +2752,7 @@ subst_stack_regs (insn, regstack)
        {
          /* This insn is an `asm' with operands.  Decode the operands,
             decide how many are inputs, and do register substitution.
-            Any REG_UNUSED notes will be handled by subst_asm_stack_regs. */
+            Any REG_UNUSED notes will be handled by subst_asm_stack_regs.  */
 
          rtx operands[MAX_RECOG_OPERANDS];
          rtx *operands_loc[MAX_RECOG_OPERANDS];
@@ -2577,7 +2781,7 @@ subst_stack_regs (insn, regstack)
     }
 
   /* subst_stack_regs_pat may have deleted a no-op insn.  If so, any
-     REG_UNUSED will already have been dealt with, so just return. */
+     REG_UNUSED will already have been dealt with, so just return.  */
 
   if (GET_CODE (insn) == NOTE)
     return;
@@ -2585,7 +2789,7 @@ subst_stack_regs (insn, regstack)
   /* If there is a REG_UNUSED note on a stack register on this insn,
      the indicated reg must be popped.  The REG_UNUSED note is removed,
      since the form of the newly emitted pop insn references the reg,
-     making it no longer `unset'. */
+     making it no longer `unset'.  */
 
   note_link = &REG_NOTES(insn);
   for (note = *note_link; note; note = XEXP (note, 1))
@@ -2608,7 +2812,7 @@ subst_stack_regs (insn, regstack)
    will be the same as NEW upon return.
 
    This function will not preserve block_end[].  But that information
-   is no longer needed once this has executed. */
+   is no longer needed once this has executed.  */
 
 static void
 change_stack (insn, old, new, when)
@@ -2626,17 +2830,17 @@ change_stack (insn, old, new, when)
   if (when == emit_insn_after)
     insn = NEXT_INSN (insn);
 
-  /* Pop any registers that are not needed in the new block. */
+  /* Pop any registers that are not needed in the new block.  */
 
   for (reg = old->top; reg >= 0; reg--)
     if (! TEST_HARD_REG_BIT (new->reg_set, old->reg[reg]))
-      emit_pop_insn (insn, old, FP_mode_reg[old->reg[reg]][(int) DFmode],
+      emit_pop_insn (insn, old, FP_MODE_REG (old->reg[reg], DFmode),
                     emit_insn_before);
 
   if (new->top == -2)
     {
       /* If the new block has never been processed, then it can inherit
-        the old stack order. */
+        the old stack order.  */
 
       new->top = old->top;
       bcopy (old->reg, new->reg, sizeof (new->reg));
@@ -2644,10 +2848,10 @@ change_stack (insn, old, new, when)
   else
     {
       /* This block has been entered before, and we must match the
-        previously selected stack order. */
+        previously selected stack order.  */
 
       /* By now, the only difference should be the order of the stack,
-        not their depth or liveliness. */
+        not their depth or liveliness.  */
 
       GO_IF_HARD_REG_EQUAL (old->reg_set, new->reg_set, win);
 
@@ -2663,12 +2867,12 @@ change_stack (insn, old, new, when)
         depth of the stack.  In some cases, the reg at the top of
         stack may be correct, but swapped anyway in order to fix
         other regs.  But since we never swap any other reg away from
-        its correct slot, this algorithm will converge. */
+        its correct slot, this algorithm will converge.  */
 
       do
        {
          /* Swap the reg at top of stack into the position it is
-            supposed to be in, until the correct top of stack appears. */
+            supposed to be in, until the correct top of stack appears.  */
 
          while (old->reg[old->top] != new->reg[new->top])
            {
@@ -2680,23 +2884,23 @@ change_stack (insn, old, new, when)
                abort ();
 
              emit_swap_insn (insn, old,
-                             FP_mode_reg[old->reg[reg]][(int) DFmode]);
+                             FP_MODE_REG (old->reg[reg], DFmode));
            }
 
          /* See if any regs remain incorrect.  If so, bring an
             incorrect reg to the top of stack, and let the while loop
-            above fix it. */
+            above fix it.  */
 
          for (reg = new->top; reg >= 0; reg--)
            if (new->reg[reg] != old->reg[reg])
              {
                emit_swap_insn (insn, old,
-                               FP_mode_reg[old->reg[reg]][(int) DFmode]);
+                               FP_MODE_REG (old->reg[reg], DFmode));
                break;
              }
        } while (reg >= 0);
 
-      /* At this point there must be no differences. */
+      /* At this point there must be no differences.  */
 
       for (reg = old->top; reg >= 0; reg--)
        if (old->reg[reg] != new->reg[reg])
@@ -2712,7 +2916,7 @@ change_stack (insn, old, new, when)
    is the order of the register stack in INSN.
 
    Any code that is emitted here must not be later processed as part
-   of any block, as it will already contain hard register numbers. */
+   of any block, as it will already contain hard register numbers.  */
 
 static void
 goto_block_pat (insn, regstack, pat)
@@ -2727,8 +2931,13 @@ goto_block_pat (insn, regstack, pat)
   struct stack_def temp_stack;
   int reg;
 
-  if (GET_CODE (pat) != LABEL_REF)
-    {
+  switch (GET_CODE (pat))
+   {
+     case RETURN:
+       straighten_stack (PREV_INSN (insn), regstack);
+       return;
+     default:
+     {
       int i, j;
       char *fmt = GET_RTX_FORMAT (GET_CODE (pat));
 
@@ -2741,13 +2950,15 @@ goto_block_pat (insn, regstack, pat)
              goto_block_pat (insn, regstack, XVECEXP (pat, i, j));
        }
       return;
-    }
+     }
+     case LABEL_REF:;
+   }
 
   label = XEXP (pat, 0);
   if (GET_CODE (label) != CODE_LABEL)
     abort ();
 
-  /* First, see if in fact anything needs to be done to the stack at all. */
+  /* First, see if in fact anything needs to be done to the stack at all.  */
   if (INSN_UID (label) <= 0)
     return;
 
@@ -2756,7 +2967,7 @@ goto_block_pat (insn, regstack, pat)
   if (label_stack->top == -2)
     {
       /* If the target block hasn't had a stack order selected, then
-        we need merely ensure that no pops are needed. */
+        we need merely ensure that no pops are needed.  */
 
       for (reg = regstack->top; reg >= 0; reg--)
        if (! TEST_HARD_REG_BIT (label_stack->reg_set, regstack->reg[reg]))
@@ -2764,7 +2975,7 @@ goto_block_pat (insn, regstack, pat)
 
       if (reg == -1)
        {
-         /* change_stack will not emit any code in this case. */
+         /* change_stack will not emit any code in this case.  */
 
          change_stack (label, regstack, label_stack, emit_insn_after);
          return;
@@ -2784,7 +2995,7 @@ goto_block_pat (insn, regstack, pat)
      a jump around the code we are about to emit.  Emit a label for the new
      code, and point the original insn at this new label. We can't use
      redirect_jump here, because we're using fld[4] of the code labels as
-     LABEL_REF chains, no NUSES counters. */
+     LABEL_REF chains, no NUSES counters.  */
 
   new_jump = emit_jump_insn_before (gen_jump (label), label);
   record_label_references (new_jump, PATTERN (new_jump));
@@ -2797,7 +3008,7 @@ goto_block_pat (insn, regstack, pat)
   LABEL_REFS (new_label) = new_label;
 
   /* The old label_ref will no longer point to the code_label if now uses,
-     so strip the label_ref from the code_label's chain of references. */
+     so strip the label_ref from the code_label's chain of references.  */
 
   for (ref = &LABEL_REFS (label); *ref != label; ref = &LABEL_NEXTREF (*ref))
     if (*ref == pat)
@@ -2814,7 +3025,7 @@ goto_block_pat (insn, regstack, pat)
   if (JUMP_LABEL (insn) == label)
     JUMP_LABEL (insn) = new_label;
 
-  /* Now emit the needed code. */
+  /* Now emit the needed code.  */
 
   temp_stack = *regstack;
 
@@ -2823,7 +3034,7 @@ goto_block_pat (insn, regstack, pat)
 \f
 /* Traverse all basic blocks in a function, converting the register
    references in each insn from the "flat" register file that gcc uses, to
-   the stack-like registers the 387 uses. */
+   the stack-like registers the 387 uses.  */
 
 static void
 convert_regs ()
@@ -2848,7 +3059,7 @@ convert_regs ()
 
       /* Process all insns in this block.  Keep track of `next' here,
         so that we don't process any insns emitted while making
-        substitutions in INSN. */
+        substitutions in INSN.  */
 
       next = block_begin[block];
       regstack = block_stack_in[block];
@@ -2858,17 +3069,15 @@ convert_regs ()
          next = NEXT_INSN (insn);
 
          /* Don't bother processing unless there is a stack reg
-            mentioned.
-
-            ??? For now, process CALL_INSNs too to make sure that the
-            stack regs are dead after a call.  Remove this eventually. */
+            mentioned or if it's a CALL_INSN (register passing of
+            floating point values).  */
 
          if (GET_MODE (insn) == QImode || GET_CODE (insn) == CALL_INSN)
            subst_stack_regs (insn, &regstack);
 
        } while (insn != block_end[block]);
 
-      /* Something failed if the stack life doesn't match. */
+      /* Something failed if the stack life doesn't match.  */
 
       GO_IF_HARD_REG_EQUAL (regstack.reg_set, block_out_reg_set[block], win);
 
@@ -2879,12 +3088,12 @@ convert_regs ()
       /* Adjust the stack of this block on exit to match the stack of
         the target block, or copy stack information into stack of
         jump target if the target block's stack order hasn't been set
-        yet. */
+        yet.  */
 
       if (GET_CODE (insn) == JUMP_INSN)
        goto_block_pat (insn, &regstack, PATTERN (insn));
 
-      /* Likewise handle the case where we fall into the next block. */
+      /* Likewise handle the case where we fall into the next block.  */
 
       if ((block < blocks - 1) && block_drops_in[block+1])
        change_stack (insn, &regstack, &block_stack_in[block+1],
@@ -2893,18 +3102,33 @@ convert_regs ()
 
   /* If the last basic block is the end of a loop, and that loop has
      regs live at its start, then the last basic block will have regs live
-     at its end that need to be popped before the function returns. */
+     at its end that need to be popped before the function returns.  */
+
+   {
+     int value_reg_low, value_reg_high;
+     value_reg_low = value_reg_high = -1;
+      {
+        rtx retvalue;
+        if (retvalue = stack_result (current_function_decl))
+        {
+          value_reg_low = REGNO (retvalue);
+          value_reg_high = value_reg_low +
+           HARD_REGNO_NREGS (value_reg_low, GET_MODE (retvalue)) - 1;
+        }
 
-  for (reg = regstack.top; reg >= 0; reg--)
-    if (! current_function_returns_real
-       || regstack.reg[reg] != FIRST_STACK_REG)
-      insn = emit_pop_insn (insn, &regstack,
-                           FP_mode_reg[regstack.reg[reg]][(int) DFmode],
+      }
+     for (reg = regstack.top; reg >= 0; reg--)
+        if (regstack.reg[reg] < value_reg_low ||
+            regstack.reg[reg] > value_reg_high)
+           insn = emit_pop_insn (insn, &regstack,
+                           FP_MODE_REG (regstack.reg[reg], DFmode),
                            emit_insn_after);
+   }
+  straighten_stack (insn, &regstack);
 }
 \f
 /* Check expression PAT, which is in INSN, for label references.  if
-   one is found, print the block number of destination to FILE. */
+   one is found, print the block number of destination to FILE.  */
 
 static void
 print_blocks (file, insn, pat)
@@ -2943,6 +3167,7 @@ print_blocks (file, insn, pat)
 \f
 /* Write information about stack registers and stack blocks into FILE.
    This is part of making a debugging dump.  */
+
 static void
 dump_stack_info (file)
      FILE *file;
@@ -2974,14 +3199,14 @@ dump_stack_info (file)
        fprintf (file, " previous");
 
       fprintf (file, "\nlive stack registers on block entry: ");
-      for (regno = FIRST_STACK_REG; regno <= LAST_STACK_REG ; regno++)
+      for (regno = FIRST_STACK_REG; regno <= LAST_STACK_REG; regno++)
        {
          if (TEST_HARD_REG_BIT (block_stack_in[block].reg_set, regno))
            fprintf (file, "%d ", regno);
        }
 
       fprintf (file, "\nlive stack registers on block exit: ");
-      for (regno = FIRST_STACK_REG; regno <= LAST_STACK_REG ; regno++)
+      for (regno = FIRST_STACK_REG; regno <= LAST_STACK_REG; regno++)
        {
          if (TEST_HARD_REG_BIT (block_out_reg_set[block], regno))
            fprintf (file, "%d ", regno);