]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/reg-stack.c
Make it possible to prototype port-specific functions (and convert i386 to use this)
[gcc.git] / gcc / reg-stack.c
index 8b150050db90abffde58c1ef5152ab0e7187c2f0..04c2cd6001258a8d9ffe4a89a23873c103c7586f 100644 (file)
@@ -1,5 +1,5 @@
 /* Register to Stack convert for GNU compiler.
-   Copyright (C) 1992 Free Software Foundation, Inc.
+   Copyright (C) 1992, 93-98, 1999 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.
@@ -73,13 +74,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
    deleted and recreated from scratch.  REG_DEAD is never created for a
    SET_DEST, only REG_UNUSED.
 
-   Before life analysis, the mode of each insn is set based on whether
-   or not any stack registers are mentioned within that insn.  VOIDmode
-   means that no regs are mentioned anyway, and QImode means that at
-   least one pattern within the insn mentions stack registers.  This
-   information is valid until after reg_to_stack returns, and is used
-   from jump_optimize.
-
    * asm_operands:
 
    There are several rules on the usage of stack-like regs in
@@ -156,28 +150,33 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
    */
 \f
-#include <stdio.h>
 #include "config.h"
+#include "system.h"
 #include "tree.h"
 #include "rtl.h"
+#include "tm_p.h"
+#include "function.h"
 #include "insn-config.h"
 #include "regs.h"
 #include "hard-reg-set.h"
 #include "flags.h"
+#include "insn-flags.h"
+#include "toplev.h"
+#include "recog.h"
+#include "varray.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.
 
-   If TOP is -2 the stack is not yet initialized: reg_set indicates
-   which registers are live.  Stack initialization consists of placing
-   each live reg in array `reg' and setting `top' appropriately. */
+   If TOP is -2, REG[] is not yet initialized.  Stack initialization
+   consists of placing each live reg in array `reg' and setting `top'
+   appropriately.
+
+   REG_SET indicates which registers are live.  */
 
 typedef struct stack_def
 {
@@ -213,41 +212,75 @@ 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. */
-static short *block_number;
+   add insns within a block.  */
+static int *block_number;
+
+/* We use this array to cache info about insns, because otherwise we
+   spend too much time in stack_regs_mentioned_p. 
+
+   Indexed by insn UIDs.  A value of zero is uninitialized, one indicates
+   the insn uses stack registers, two indicates the insn does not use
+   stack registers.  */
+static varray_type stack_regs_mentioned_data;
 
 /* 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];
 
-/* Get the basic block number of an insn.  See note at block_number
-   definition are validity of this information. */
+#define FP_MODE_REG(regno,mode)        \
+  (FP_mode_reg[(regno)-FIRST_STACK_REG][(int)(mode)])
 
-#define BLOCK_NUM(INSN)  \
-  (((INSN_UID (INSN) > max_uid)        \
-    ? (short *)(abort() , 0)           \
-    : block_number)[INSN_UID (INSN)])
+/* Get the basic block number of an insn.  See note at block_number
+   definition are validity of this information.  */
 
-extern rtx gen_jump ();
-extern rtx gen_movdf ();
-extern rtx find_regno_note ();
-extern rtx emit_jump_insn_before ();
-extern rtx emit_label_after ();
+#define BLOCK_NUM(INSN)                                        \
+  ((INSN_UID (INSN) > max_uid)                         \
+   ? (abort() , -1) : block_number[INSN_UID (INSN)])
 
 /* Forward declarations */
 
-static void find_blocks ();
-static void stack_reg_life_analysis ();
-static void change_stack ();
-static void convert_regs ();
-static void dump_stack_info ();
+static int stack_regs_mentioned_p      PROTO((rtx pat));
+static void mark_regs_pat              PROTO((rtx, HARD_REG_SET *));
+static void straighten_stack           PROTO((rtx, stack));
+static void pop_stack                  PROTO((stack, int));
+static void record_label_references    PROTO((rtx, rtx));
+static rtx *get_true_reg               PROTO((rtx *));
+
+static void record_asm_reg_life                PROTO((rtx, stack));
+static void record_reg_life_pat                PROTO((rtx, HARD_REG_SET *,
+                                              HARD_REG_SET *, int));
+static int get_asm_operand_n_inputs    PROTO((rtx));
+static void record_reg_life            PROTO((rtx, int, stack));
+static void find_blocks                        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 int swap_rtx_condition_1                PROTO((rtx));
+static int 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));
+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
 /* Return non-zero if any stack register is mentioned somewhere within PAT.  */
 
-int
+static int
 stack_regs_mentioned_p (pat)
-     register rtx pat;
+     rtx pat;
 {
-  register char *fmt;
+  register const char *fmt;
   register int i;
 
   if (STACK_REG_P (pat))
@@ -270,6 +303,143 @@ stack_regs_mentioned_p (pat)
 
   return 0;
 }
+
+/* Return nonzero if INSN mentions stacked registers, else return zero.  */
+
+int
+stack_regs_mentioned (insn)
+     rtx insn;
+{
+  unsigned int uid, max;
+  int test;
+
+  if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
+    return 0;
+
+  uid = INSN_UID (insn);
+  max = VARRAY_SIZE (stack_regs_mentioned_data);
+  if (uid >= max)
+    {
+      /* Allocate some extra size to avoid too many reallocs, but
+        do not grow too quickly.  */
+      max = uid + uid / 20;
+      VARRAY_GROW (stack_regs_mentioned_data, max);
+    }
+
+  test = VARRAY_CHAR (stack_regs_mentioned_data, uid);
+  if (test == 0)
+    {
+      /* This insn has yet to be examined.  Do so now.  */
+      test = stack_regs_mentioned_p (PATTERN (insn)) ? 1 : 2;
+      VARRAY_CHAR (stack_regs_mentioned_data, uid) = test;
+    }
+
+  return test == 1;
+}
+\f
+static rtx ix86_flags_rtx;
+
+static rtx
+next_flags_user (insn)
+     rtx insn;
+{
+  /* Search forward looking for the first use of this value. 
+     Stop at block boundaries.  */
+  /* ??? This really cries for BLOCK_END!  */
+
+  while (1)
+    {
+      insn = NEXT_INSN (insn);
+      if (!insn)
+       return NULL_RTX;
+
+      if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
+          && reg_mentioned_p (ix86_flags_rtx, PATTERN (insn)))
+        return insn;
+
+      if (GET_CODE (insn) == JUMP_INSN
+         || GET_CODE (insn) == CODE_LABEL
+         || GET_CODE (insn) == CALL_INSN)
+       return NULL_RTX;
+    }
+}
+\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;
+
+  /* If there is only a single register on the stack, then the stack is
+     already in increasing order and no reorganization is needed.
+
+     Similarly if the stack is empty.  */
+  if (regstack->top <= 0)
+    return;
+
+  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);
+}
+
+/* Pop a register from the stack */
+
+static void
+pop_stack (regstack, regno)
+     stack regstack;
+     int   regno;
+{
+  int top = regstack->top;
+
+  CLEAR_HARD_REG_BIT (regstack->reg_set, regno);
+  regstack->top--;
+  /* If regno was not at the top of stack then adjust stack */
+  if (regstack->reg [top] != regno)
+    {
+      int i;
+      for (i = regstack->top; i >= 0; i--)
+       if (regstack->reg [i] == regno)
+         {
+           int j;
+           for (j = i; j < top; j++)
+             regstack->reg [j] = regstack->reg [j + 1];
+           break;
+         }
+    }
+}
 \f
 /* Convert register usage from "flat" register file usage to a "stack
    register file.  FIRST is the first insn in the function, FILE is the
@@ -290,26 +460,51 @@ reg_to_stack (first, file)
   register int i;
   int stack_reg_seen = 0;
   enum machine_mode mode;
+  HARD_REG_SET stackentry;
+
+  ix86_flags_rtx = gen_rtx_REG (CCmode, FLAGS_REG);
+
+  max_uid = get_max_uid ();
+  VARRAY_CHAR_INIT (stack_regs_mentioned_data, max_uid + 1,
+                   "stack_regs_mentioned cache");
 
-  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 int 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 = JUMP_INSN;
+    register RTX_CODE prev_code = BARRIER;
     register RTX_CODE code;
+    register int before_function_beg = 1;
 
     max_uid = 0;
     blocks = 0;
     for (insn = first; insn; insn = NEXT_INSN (insn))
       {
        /* Note that this loop must select the same block boundaries
-          as code in find_blocks. */
+          as code in find_blocks.  Also note that this code is not the
+          same as that used in flow.c.  */
 
        if (INSN_UID (insn) > max_uid)
          max_uid = INSN_UID (insn);
@@ -320,21 +515,33 @@ reg_to_stack (first, file)
            || (prev_code != INSN
                && prev_code != CALL_INSN
                && prev_code != CODE_LABEL
-               && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
+               && 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_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
-            || GET_CODE (insn) == JUMP_INSN)
+       if (GET_RTX_CLASS (code) == 'i'
            && stack_regs_mentioned_p (PATTERN (insn)))
          {
            stack_reg_seen = 1;
-           PUT_MODE (insn, QImode);
+           VARRAY_CHAR (stack_regs_mentioned_data, INSN_UID (insn)) = 1;
+
+           /* 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);
+         VARRAY_CHAR (stack_regs_mentioned_data, INSN_UID (insn)) = 2;
+
+       if (code == CODE_LABEL)
+         LABEL_REFS (insn) = insn; /* delete old chain */
 
        if (code != NOTE)
          prev_code = code;
@@ -345,15 +552,18 @@ reg_to_stack (first, file)
      anything to convert.  */
 
   if (! stack_reg_seen)
-    return;
+    {
+      VARRAY_FREE (stack_regs_mentioned_data);
+      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));
@@ -361,17 +571,17 @@ reg_to_stack (first, file)
 
   block_stack_in = (stack) alloca (blocks * sizeof (struct stack_def));
   block_out_reg_set = (HARD_REG_SET *) alloca (blocks * sizeof (HARD_REG_SET));
-  bzero (block_stack_in, blocks * sizeof (struct stack_def));
-  bzero (block_out_reg_set, blocks * sizeof (HARD_REG_SET));
+  bzero ((char *) block_stack_in, blocks * sizeof (struct stack_def));
+  bzero ((char *) block_out_reg_set, blocks * sizeof (HARD_REG_SET));
 
-  block_number = (short *) alloca ((max_uid + 1) * sizeof (short));
+  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);
@@ -380,11 +590,13 @@ reg_to_stack (first, file)
 
   if (optimize)
     jump_optimize (first, 2, 0, 0);
+
+  VARRAY_FREE (stack_regs_mentioned_data);
 }
 \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)
@@ -392,7 +604,7 @@ record_label_references (insn, pat)
 {
   register enum rtx_code code = GET_CODE (pat);
   register int i;
-  register char *fmt;
+  register const char *fmt;
 
   if (code == LABEL_REF)
     {
@@ -402,9 +614,16 @@ 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 != label; ref = LABEL_NEXTREF (ref))
+      for (ref = LABEL_REFS (label);
+          ref && ref != label;
+          ref = LABEL_NEXTREF (ref))
        if (CONTAINING_INSN (ref) == insn)
          return;
 
@@ -431,384 +650,84 @@ 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
-        || GET_CODE (*pat) == FLOAT_TRUNCATE)
-    pat = & XEXP (*pat, 0);
-
-  return pat;
-}
-
-/* If REG is a stack register that is marked dead in REGSTACK, then
-   record that it is now live. If REG is not DEST, add a death note to
-   INSN if there isn't one already.  If DEST is not a reg, it is safe to
-   assume that it does not mention a reg anywhere within. */
-
-static void
-record_note_if_dead (insn, regstack, reg, dest)
-     rtx insn;
-     stack regstack;
-     rtx reg, dest;
-{
-  reg = * get_true_reg (& reg);
-
-  if (STACK_REG_P (reg))
-    {
-      if (! TEST_HARD_REG_BIT (regstack->reg_set, REGNO (reg)))
-       {
-         if ((! REG_P (dest) || REGNO (dest) != REGNO (reg))
-             && ! find_regno_note (insn, REG_DEAD, REGNO (reg)))
-           REG_NOTES (insn) = gen_rtx (EXPR_LIST,
-                                       REG_DEAD, reg, REG_NOTES (insn));
-
-         SET_HARD_REG_BIT (regstack->reg_set, REGNO (reg));
-       }
-    }
-  else
-    if (stack_regs_mentioned_p (reg))
-      abort ();
-}
-\f
-/* Scan the OPERANDS and OPERAND_CONSTRAINTS of an asm_operands.
-   N_OPERANDS is the total number of operands.  Return which alternative
-   matched, or -1 is no alternative matches.
-
-   OPERAND_MATCHES is an array which indicates which operand this
-   operand matches due to the constraints, or -1 if no match is required.
-   If two operands match by coincidence, but are not required to match by
-   the constraints, -1 is returned.
-
-   OPERAND_CLASS is an array which indicates the smallest class
-   required by the constraints.  If the alternative that matches calls
-   for some class `class', and the operand matches a subclass of `class',
-   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. */
-
-static int
-constrain_asm_operands (n_operands, operands, operand_constraints,
-                       operand_matches, operand_class)
-     int n_operands;
-     rtx *operands;
-     char **operand_constraints;
-     int *operand_matches;
-     enum reg_class *operand_class;
-{
-  char **constraints = (char **) alloca (n_operands * sizeof (char *));
-  char *q;
-  int this_alternative, this_operand;
-  int n_alternatives;
-  int j;
-
-  for (j = 0; j < n_operands; j++)
-    constraints[j] = operand_constraints[j];
-
-  /* Compute the number of alternatives in the operands.  reload has
-     already guaranteed that all operands have the same number of
-     alternatives.  */
-
-  n_alternatives = 1;
-  for (q = constraints[0]; *q; q++)
-    n_alternatives += (*q == ',');
-
-  this_alternative = 0;
-  while (this_alternative < n_alternatives)
-    {
-      int lose = 0;
-      int i;
-
-      /* No operands match, no narrow class requirements yet.  */
-      for (i = 0; i < n_operands; i++)
-       {
-         operand_matches[i] = -1;
-         operand_class[i] = NO_REGS;
-       }
-
-      for (this_operand = 0; this_operand < n_operands; this_operand++)
+  for (;;)
+    switch (GET_CODE (*pat))
+      {
+      case SUBREG:
+       /* Eliminate FP subregister accesses in favour of the
+          actual FP register in use.  */
        {
-         rtx op = operands[this_operand];
-         enum machine_mode mode = GET_MODE (op);
-         char *p = constraints[this_operand];
-         int offset = 0;
-         int win = 0;
-         int c;
-
-         if (GET_CODE (op) == SUBREG)
+         rtx subreg;
+         if (FP_REG_P (subreg = SUBREG_REG (*pat)))
            {
-             if (GET_CODE (SUBREG_REG (op)) == REG
-                 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
-               offset = SUBREG_WORD (op);
-             op = SUBREG_REG (op);
+             *pat = FP_MODE_REG (REGNO (subreg) + SUBREG_WORD (*pat),
+                                 GET_MODE (subreg));
+           default:
+             return pat;
            }
-
-         /* An empty constraint or empty alternative
-            allows anything which matched the pattern.  */
-         if (*p == 0 || *p == ',')
-           win = 1;
-
-         while (*p && (c = *p++) != ',')
-           switch (c)
-             {
-             case '=':
-             case '+':
-             case '?':
-             case '&':
-             case '!':
-             case '*':
-             case '%':
-               /* Ignore these. */
-               break;
-
-             case '#':
-               /* Ignore rest of this alternative. */
-               while (*p && *p != ',') p++;
-               break;
-
-             case '0':
-             case '1':
-             case '2':
-             case '3':
-             case '4':
-             case '5':
-               /* This operand must be the same as a previous one.
-                  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. */
-
-               if (operands_match_p (operands[c - '0'],
-                                     operands[this_operand]))
-                 {
-                   operand_matches[this_operand] = c - '0';
-                   win = 1;
-                 }
-               break;
-
-             case 'p':
-               /* p is used for address_operands.  Since this is an asm,
-                  just to make sure that the operand is valid for Pmode. */
-
-               if (strict_memory_address_p (Pmode, op))
-                 win = 1;
-               break;
-
-             case 'g':
-               /* Anything goes unless it is a REG and really has a hard reg
-                  but the hard reg is not in the class GENERAL_REGS.  */
-               if (GENERAL_REGS == ALL_REGS
-                   || GET_CODE (op) != REG
-                   || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
-                 {
-                   if (GET_CODE (op) == REG)
-                     operand_class[this_operand]
-                       = reg_class_subunion[(int) operand_class[this_operand]][(int) GENERAL_REGS];
-                   win = 1;
-                 }
-               break;
-
-             case 'r':
-               if (GET_CODE (op) == REG
-                   && (GENERAL_REGS == ALL_REGS
-                       || reg_fits_class_p (op, GENERAL_REGS, offset, mode)))
-                 {
-                   operand_class[this_operand]
-                     = reg_class_subunion[(int) operand_class[this_operand]][(int) GENERAL_REGS];
-                   win = 1;
-                 }
-               break;
-
-             case 'X':
-               /* This is used for a MATCH_SCRATCH in the cases when we
-                  don't actually need anything.  So anything goes any time. */
-               win = 1;
-               break;
-
-             case 'm':
-               if (GET_CODE (op) == MEM)
-                 win = 1;
-               break;
-
-             case '<':
-               if (GET_CODE (op) == MEM
-                   && (GET_CODE (XEXP (op, 0)) == PRE_DEC
-                       || GET_CODE (XEXP (op, 0)) == POST_DEC))
-                 win = 1;
-               break;
-
-             case '>':
-               if (GET_CODE (op) == MEM
-                   && (GET_CODE (XEXP (op, 0)) == PRE_INC
-                       || GET_CODE (XEXP (op, 0)) == POST_INC))
-                 win = 1;
-               break;
-
-             case 'E':
-               /* Match any CONST_DOUBLE, but only if
-                  we can examine the bits of it reliably.  */
-               if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
-                    || HOST_BITS_PER_INT != BITS_PER_WORD)
-                   && GET_CODE (op) != VOIDmode && ! flag_pretend_float)
-                 break;
-               if (GET_CODE (op) == CONST_DOUBLE)
-                 win = 1;
-               break;
-
-             case 'F':
-               if (GET_CODE (op) == CONST_DOUBLE)
-                 win = 1;
-               break;
-
-             case 'G':
-             case 'H':
-               if (GET_CODE (op) == CONST_DOUBLE
-                   && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
-                 win = 1;
-               break;
-
-             case 's':
-               if (GET_CODE (op) == CONST_INT
-                   || (GET_CODE (op) == CONST_DOUBLE
-                       && GET_MODE (op) == VOIDmode))
-                 break;
-               /* Fall through */
-             case 'i':
-               if (CONSTANT_P (op))
-                 win = 1;
-               break;
-
-             case 'n':
-               if (GET_CODE (op) == CONST_INT
-                   || (GET_CODE (op) == CONST_DOUBLE
-                       && GET_MODE (op) == VOIDmode))
-                 win = 1;
-               break;
-
-             case 'I':
-             case 'J':
-             case 'K':
-             case 'L':
-             case 'M':
-             case 'N':
-             case 'O':
-             case 'P':
-               if (GET_CODE (op) == CONST_INT
-                   && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
-                 win = 1;
-               break;
-
-#ifdef EXTRA_CONSTRAINT
-              case 'Q':
-              case 'R':
-              case 'S':
-              case 'T':
-              case 'U':
-               if (EXTRA_CONSTRAINT (op, c))
-                 win = 1;
-               break;
-#endif
-
-             case 'V':
-               if (GET_CODE (op) == MEM && ! offsettable_memref_p (op))
-                 win = 1;
-               break;
-
-             case 'o':
-               if (offsettable_memref_p (op))
-                 win = 1;
-               break;
-
-             default:
-               if (GET_CODE (op) == REG
-                   && reg_fits_class_p (op, REG_CLASS_FROM_LETTER (c),
-                                        offset, mode))
-                 {
-                   operand_class[this_operand]
-                     = reg_class_subunion[(int)operand_class[this_operand]][(int) REG_CLASS_FROM_LETTER (c)];
-                   win = 1;
-                 }
-             }
-
-         constraints[this_operand] = p;
-         /* If this operand did not win somehow,
-            this alternative loses.  */
-         if (! win)
-           lose = 1;
        }
-      /* This alternative won; the operands are ok.
-        Change whichever operands this alternative says to change.  */
-      if (! lose)
-       break;
-
-      this_alternative++;
-    }
-
-  /* For operands constrained to match another operand, copy the other
-     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]];
-
-  return this_alternative == n_alternatives ? -1 : this_alternative;
+      case FLOAT:
+      case FIX:
+      case FLOAT_EXTEND:
+       pat = & XEXP (*pat, 0);
+      }
 }
 \f
 /* Record the life info of each stack reg in INSN, updating REGSTACK.
-   N_INPUTS is the number of inputs; N_OUTPUTS the outputs.  CONSTRAINTS
-   is an array of the constraint strings used in the asm statement.
-   OPERANDS is an array of all operands for the insn, and is assumed to
-   contain all output operands, then all inputs operands.
+   N_INPUTS is the number of inputs; N_OUTPUTS the outputs.
 
    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,
-                    n_inputs, n_outputs)
+record_asm_reg_life (insn, regstack)
      rtx insn;
      stack regstack;
-     rtx *operands;
-     char **constraints;
-     int n_inputs, n_outputs;
 {
   int i;
-  int n_operands = n_inputs + n_outputs;
-  int first_input = n_outputs;
   int n_clobbers;
   int malformed_asm = 0;
   rtx body = PATTERN (insn);
 
-  int *operand_matches = (int *) alloca (n_operands * sizeof (int *));
-
-  enum reg_class *operand_class 
-    = (enum reg_class *) alloca (n_operands * sizeof (enum reg_class *));
-
   int reg_used_as_output[FIRST_PSEUDO_REGISTER];
   int implicitly_dies[FIRST_PSEUDO_REGISTER];
+  int alt;
 
   rtx *clobber_reg;
+  int n_inputs, n_outputs;
 
-  /* Find out what the constraints required.  If no constraint
-     alternative matches, that is a compiler bug: we should have caught
-     such an insn during reload.  */
-  i = constrain_asm_operands (n_operands, operands, constraints,
-                             operand_matches, operand_class);
-  if (i < 0)
-    abort ();
+  /* Find out what the constraints require.  If no constraint
+     alternative matches, this asm is malformed.  */
+  extract_insn (insn);
+  constrain_operands (1);
+  alt = which_alternative;
+
+  preprocess_constraints ();
+
+  n_inputs = get_asm_operand_n_inputs (body);
+  n_outputs = recog_data.n_operands - n_inputs;
+
+  if (alt < 0)
+    {
+      malformed_asm = 1;
+      /* Avoid further trouble with this insn.  */
+      PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
+      PUT_MODE (insn, VOIDmode);
+      return;
+    }
 
-  /* 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)
-      operands[i] = SUBREG_REG (operands[i]);
+  /* Strip SUBREGs here to make the following code simpler.  */
+  for (i = 0; i < recog_data.n_operands; i++)
+    if (GET_CODE (recog_data.operand[i]) == SUBREG
+       && GET_CODE (SUBREG_REG (recog_data.operand[i])) == REG)
+      recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
 
   /* Set up CLOBBER_REG.  */
 
@@ -816,7 +735,7 @@ record_asm_reg_life (insn, regstack, operands, constraints,
 
   if (GET_CODE (body) == PARALLEL)
     {
-      clobber_reg = (rtx *) alloca (XVECLEN (body, 0) * sizeof (rtx *));
+      clobber_reg = (rtx *) alloca (XVECLEN (body, 0) * sizeof (rtx));
 
       for (i = 0; i < XVECLEN (body, 0); i++)
        if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
@@ -840,19 +759,20 @@ 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 (reg_used_as_output, sizeof (reg_used_as_output));
+  bzero ((char *) reg_used_as_output, sizeof (reg_used_as_output));
   for (i = 0; i < n_outputs; i++)
-    if (STACK_REG_P (operands[i]))
-      if (reg_class_size[operand_class[i]] != 1)
-       {
-         error_for_asm
-           (insn, "Output constraint %d must specify a single register", i);
-         malformed_asm = 1;
-       }
-      else
-       reg_used_as_output[REGNO (operands[i])] = 1;
+    if (STACK_REG_P (recog_data.operand[i]))
+      {
+       if (reg_class_size[(int) recog_op_alt[i][alt].class] != 1)
+         {
+           error_for_asm (insn, "Output constraint %d must specify a single register", i);
+           malformed_asm = 1;
+         }
+        else
+         reg_used_as_output[REGNO (recog_data.operand[i])] = 1;
+      }
 
 
   /* Search for first non-popped reg.  */
@@ -873,22 +793,22 @@ 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 (implicitly_dies, sizeof (implicitly_dies));
-  for (i = first_input; i < first_input + n_inputs; i++)
-    if (STACK_REG_P (operands[i]))
+  bzero ((char *) implicitly_dies, sizeof (implicitly_dies));
+  for (i = n_outputs; i < n_outputs + n_inputs; i++)
+    if (STACK_REG_P (recog_data.operand[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++)
-         if (operands_match_p (clobber_reg[j], operands[i]))
+         if (operands_match_p (clobber_reg[j], recog_data.operand[i]))
            break;
 
-       if (j < n_clobbers || operand_matches[i] >= 0)
-         implicitly_dies[REGNO (operands[i])] = 1;
+       if (j < n_clobbers || recog_op_alt[i][alt].matches >= 0)
+         implicitly_dies[REGNO (recog_data.operand[i])] = 1;
       }
 
   /* Search for first non-popped reg.  */
@@ -912,15 +832,15 @@ 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)
+  for (i = n_outputs; i < n_outputs + n_inputs; i++)
+    if (recog_op_alt[i][alt].matches == -1)
       {
        int j;
 
        for (j = 0; j < n_outputs; j++)
-         if (operands_match_p (operands[j], operands[i]))
+         if (operands_match_p (recog_data.operand[j], recog_data.operand[i]))
            {
              error_for_asm (insn,
                             "Output operand %d must use `&' constraint", j);
@@ -931,184 +851,137 @@ record_asm_reg_life (insn, regstack, operands, constraints,
   if (malformed_asm)
     {
       /* Avoid further trouble with this insn.  */
-      PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
-      PUT_MODE (insn, VOIDmode);
+      PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
+      VARRAY_CHAR (stack_regs_mentioned_data, INSN_UID (insn)) = 2;
       return;
     }
 
   /* Process all outputs */
   for (i = 0; i < n_outputs; i++)
     {
-      rtx op = operands[i];
+      rtx op = recog_data.operand[i];
 
       if (! STACK_REG_P (op))
-       if (stack_regs_mentioned_p (op))
-         abort ();
-       else
-         continue;
+       {
+         if (stack_regs_mentioned_p (op))
+           abort ();
+         else
+           continue;
+       }
 
       /* Each destination is dead before this insn.  If the
         destination is not used after this insn, record this with
         REG_UNUSED.  */
 
       if (! TEST_HARD_REG_BIT (regstack->reg_set, REGNO (op)))
-       REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_UNUSED, op,
-                                   REG_NOTES (insn));
+       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_UNUSED, op,
+                                             REG_NOTES (insn));
 
       CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (op));
     }
 
   /* Process all inputs */
-  for (i = first_input; i < first_input + n_inputs; i++)
+  for (i = n_outputs; i < n_outputs + n_inputs; i++)
     {
-      if (! STACK_REG_P (operands[i]))
-       if (stack_regs_mentioned_p (operands[i]))
-         abort ();
-       else
-         continue;
+      rtx op = recog_data.operand[i];
+      if (! STACK_REG_P (op))
+       {
+         if (stack_regs_mentioned_p (op))
+           abort ();
+         else
+           continue;
+       }
 
       /* If an input is dead after the insn, record a death note.
         But don't record a death note if there is already a death note,
         or if the input is also an output.  */
 
-      if (! TEST_HARD_REG_BIT (regstack->reg_set, REGNO (operands[i]))
-         && operand_matches[i] == -1
-         && ! find_regno_note (insn, REG_DEAD, REGNO (operands[i])))
-       REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_DEAD, operands[i],
-                                   REG_NOTES (insn));
+      if (! TEST_HARD_REG_BIT (regstack->reg_set, REGNO (op))
+         && recog_op_alt[i][alt].matches == -1
+         && find_regno_note (insn, REG_DEAD, REGNO (op)) == NULL_RTX)
+       REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_DEAD, op, REG_NOTES (insn));
 
-      SET_HARD_REG_BIT (regstack->reg_set, REGNO (operands[i]));
+      SET_HARD_REG_BIT (regstack->reg_set, REGNO (op));
     }
 }
 
-/* Scan PAT, which is part of INSN, and record the life & death of
-   stack registers in REGSTACK.  If a register was dead, but is an input
-   operand in this insn, then mark the register live and record a death
-   note.
-
-   If a register is dead after this insn, but is an output operand in
-   this insn, record a REG_UNUSED note.
+/* Scan PAT, which is part of INSN, and record registers appearing in
+   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.  */
 
 static void
-record_reg_life_pat (insn, regstack, pat)
-     rtx insn;
-     stack regstack;
+record_reg_life_pat (pat, src, dest, douse)
      rtx pat;
+     HARD_REG_SET *src, *dest;
+     int douse;
 {
-  rtx src, dest;
-
-  /* We should have already handled any asm.  */
-  if (GET_CODE (pat) == ASM_INPUT || GET_CODE (pat) == ASM_OPERANDS)
-    abort ();
-
-  if (GET_CODE (pat) != SET)
-    return;
-
-  dest = * get_true_reg (& SET_DEST (pat));
-
-  /* The destination is dead before this insn.  If the destination is
-     not used after this insn, record this with REG_UNUSED. */
+  register const char *fmt;
+  register int i;
 
-  if (STACK_REG_P (dest))
+  if (STACK_REG_P (pat)
+      || (GET_CODE (pat) == SUBREG && STACK_REG_P (SUBREG_REG (pat))))
     {
-      /* ??? This check is unnecessary. */
+      if (src)
+       mark_regs_pat (pat, src);
 
-      if (find_regno_note (insn, REG_UNUSED, REGNO (dest)))
-       abort ();
-
-      if (! TEST_HARD_REG_BIT (regstack->reg_set, REGNO (dest)))
-       REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_UNUSED, dest,
-                                   REG_NOTES (insn));
+      if (dest)
+       mark_regs_pat (pat, dest);
 
-      CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
+      return;
     }
-  else
-    if (dest != cc0_rtx && stack_regs_mentioned_p (dest))
-      abort ();
 
-  src = * get_true_reg (& SET_SRC (pat));
-
-  switch (GET_CODE (src))
+  if (GET_CODE (pat) == SET)
     {
-      /* ??? get_true_reg will make some of these cases redundant. */
-
-    case PLUS:
-    case MINUS:
-    case MULT:
-    case DIV:
-    case COMPARE:
-      record_note_if_dead (insn, regstack, XEXP (src, 0), dest);
-      record_note_if_dead (insn, regstack, XEXP (src, 1), dest);
-      break;
-
-    case ABS:
-    case NEG:
-    case SQRT:
-    case FLOAT_EXTEND:
-    case FLOAT_TRUNCATE:
-    case FLOAT:
-    case UNSIGNED_FLOAT:
-      record_note_if_dead (insn, regstack, XEXP (src, 0), dest);
-      break;
-
-    case UNSIGNED_FIX:
-    case FIX:
-      src = XEXP (src, 0);
-      if (GET_CODE (src) == FIX)
-       record_note_if_dead (insn, regstack, XEXP (src, 0), dest);
-      else
-       record_note_if_dead (insn, regstack, src, dest);
-      break;
-
-    case ASM_OPERANDS:
-    case ASM_INPUT:
-      abort ();  /* we should have caught this already. */
-      break;
+      record_reg_life_pat (XEXP (pat, 0), NULL_PTR, dest, 0);
+      record_reg_life_pat (XEXP (pat, 1), src, NULL_PTR, 0);
+      return;
+    }
 
-    case REG:
-      record_note_if_dead (insn, regstack, src, dest);
-      break;
+  /* We don't need to consider either of these cases.  */
+  if ((GET_CODE (pat) == USE && !douse) || GET_CODE (pat) == CLOBBER)
+    return;
 
-    default:
-      /* If a stack register appears in the src RTL, it is a bug, and
-        code should be added above to handle it. */
+  fmt = GET_RTX_FORMAT (GET_CODE (pat));
+  for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
+    {
+      if (fmt[i] == 'E')
+       {
+         register int j;
 
-      if (stack_regs_mentioned_p (src))
-       abort ();
+         for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
+           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, 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)
+static int
+get_asm_operand_n_inputs (body)
      rtx body;
-     int n_operands;
-     int *n_inputs, *n_outputs;
 {
   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
-    *n_inputs = ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body));
+    return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body));
 
   else if (GET_CODE (body) == ASM_OPERANDS)
-    *n_inputs = ASM_OPERANDS_INPUT_LENGTH (body);
+    return ASM_OPERANDS_INPUT_LENGTH (body);
 
   else if (GET_CODE (body) == PARALLEL
           && GET_CODE (XVECEXP (body, 0, 0)) == SET)
-    *n_inputs = ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)));
+    return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)));
 
   else if (GET_CODE (body) == PARALLEL
           && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
-    *n_inputs = ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
-  else
-    abort ();
+    return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
 
-  *n_outputs = n_operands - *n_inputs;
+  abort ();
 }
 \f
 /* Scan INSN, which is in BLOCK, and record the life & death of stack
@@ -1121,7 +994,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)
@@ -1147,83 +1020,87 @@ 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. */
-
-      rtx operands[MAX_RECOG_OPERANDS];
-      rtx body = PATTERN (insn);
-      int n_inputs, n_outputs;
-      char **constraints = (char **) alloca (n_operands * sizeof (char *));
-
-      decode_asm_operands (body, operands, 0, constraints, 0);
-      get_asm_operand_lengths (body, n_operands, &n_inputs, &n_outputs);
-      record_asm_reg_life (insn, regstack, operands, constraints,
-                          n_inputs, n_outputs);
+      record_asm_reg_life (insn, regstack);
       return;
     }
 
-  if (GET_CODE (PATTERN (insn)) == PARALLEL)
-    {
-      register int i;
-
-      for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
-       record_reg_life_pat (insn, regstack, XVECEXP (PATTERN (insn), 0, i));
-    }
-  else if (GET_MODE (insn) == QImode)
-    record_reg_life_pat (insn, regstack, PATTERN (insn));
-
-  /* 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;
+  {
+    HARD_REG_SET src, dest;
+    int regno;
+
+    CLEAR_HARD_REG_SET (src);
+    CLEAR_HARD_REG_SET (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, 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, DFmode),
+                                                 REG_NOTES (insn));
+       }
 
-      /* If a stack reg is mentioned in a CALL_INSN, it must be as the
-        return value; conversely, if a float is returned, a stack reg
-        must be mentioned. */
+    if (GET_CODE (insn) == CALL_INSN)
+      {
+       int reg;
 
-      if (stack_regs_mentioned_p (PATTERN (insn)))
-       reg++;
+       /* 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().  */
 
-      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);
 
-           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)
@@ -1233,15 +1110,17 @@ find_blocks (first)
   register int block;
   register RTX_CODE prev_code = BARRIER;
   register RTX_CODE code;
+  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))
     {
       /* Note that this loop must select the same block boundaries
-        as code in reg_to_stack. */
+        as code in reg_to_stack, but that these are not the same
+        as those selected in flow.c.  */
 
       code = GET_CODE (insn);
 
@@ -1249,19 +1128,27 @@ find_blocks (first)
          || (prev_code != INSN
              && prev_code != CALL_INSN
              && prev_code != CODE_LABEL
-             && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
+             && GET_RTX_CLASS (code) == 'i'))
        {
          block_begin[++block] = insn;
          block_end[block] = insn;
          block_drops_in[block] = prev_code != BARRIER;
        }
-      else if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
+      else if (GET_RTX_CLASS (code) == 'i')
        block_end[block] = insn;
 
-      BLOCK_NUM (insn) = block;
+      if (GET_RTX_CLASS (code) == 'i')
+       {
+         rtx note;
+
+         /* Make a list of all labels referred to other than by jumps.  */
+         for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
+           if (REG_NOTE_KIND (note) == REG_LABEL)
+             label_value_list = gen_rtx_EXPR_LIST (VOIDmode, XEXP (note, 0),
+                                                   label_value_list);
+       }
 
-      if (code == CODE_LABEL)
-       LABEL_REFS (insn) = insn; /* delete old chain */
+      block_number[INSN_UID (insn)] = block;
 
       if (code != NOTE)
        prev_code = code;
@@ -1276,9 +1163,51 @@ find_blocks (first)
       insn = block_end[block];
 
       if (GET_CODE (insn) == JUMP_INSN)
-       record_label_references (insn, PATTERN (insn));
+       {
+         rtx pat = PATTERN (insn);
+         rtx x;
+
+         if (computed_jump_p (insn))
+           {
+             for (x = label_value_list; x; x = XEXP (x, 1))
+               record_label_references (insn,
+                                        gen_rtx_LABEL_REF (VOIDmode,
+                                                           XEXP (x, 0)));
+
+             for (x = forced_labels; x; x = XEXP (x, 1))
+               record_label_references (insn,
+                                        gen_rtx_LABEL_REF (VOIDmode,
+                                                           XEXP (x, 0)));
+           }
+
+         record_label_references (insn, pat);
+       }
     }
 }
+
+/* If current function returns its result in an fp stack register,
+   return the REG.  Otherwise, return 0.  */
+
+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))
+    {
+#ifdef FUNCTION_OUTGOING_VALUE
+      result
+        = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (decl)), decl);
+#else
+      result = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (decl)), decl);
+#endif
+    }
+
+  return result != 0 && STACK_REG_P (result) ? result : 0;
+}
 \f
 /* Determine the which registers are live at the start of each basic
    block of the function whose first insn is FIRST.
@@ -1289,7 +1218,7 @@ find_blocks (first)
 
    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
@@ -1308,31 +1237,36 @@ find_blocks (first)
 
    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)
-    {
-      /* Find all RETURN insns and mark them. */
+  {
+    rtx retvalue;
+
+    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], FIRST_STACK_REG);
+        for (block = blocks - 1; --block >= 0;)
+         if (GET_CODE (block_end[block]) == JUMP_INSN
+             && returnjump_p (block_end[block]))
+           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], FIRST_STACK_REG);
-    }
+        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 */
 
@@ -1353,21 +1287,21 @@ 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)
+         if (stack_regs_mentioned (insn) || GET_CODE (insn) == CALL_INSN)
            record_reg_life (insn, block, &regstack);
 
        } 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)
        {
@@ -1388,7 +1322,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],
@@ -1399,6 +1333,7 @@ stack_reg_life_analysis (first)
 
                  block = jump_block;
                  must_restart = 1;
+                 break;
 
                win:
                  ;
@@ -1415,53 +1350,43 @@ 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);
-  }
+  /* 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.  */
 
   /* 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],
-                           CONST0_RTX (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
-/*****************************************************************************
  This section deals with stack register substitution, and forms the second
  pass over the RTL.
- *****************************************************************************/
+/*
* This section deals with stack register substitution, and forms the second
* pass over the RTL.
+ */
 
 /* 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)
@@ -1472,14 +1397,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)
@@ -1505,7 +1434,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)
@@ -1526,7 +1455,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)
@@ -1535,7 +1464,6 @@ delete_insn_for_stacker (insn)
   PUT_CODE (insn, NOTE);
   NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
   NOTE_SOURCE_FILE (insn) = 0;
-  INSN_DELETED_P (insn) = 1;
 }
 \f
 /* Emit an insn to pop virtual register REG before or after INSN.
@@ -1543,7 +1471,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)
@@ -1560,15 +1488,14 @@ 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);
-  PUT_MODE (pop_insn, VOIDmode);
 
-  REG_NOTES (pop_insn) = gen_rtx (EXPR_LIST, REG_DEAD,
-                                 FP_mode_reg[FIRST_STACK_REG][(int) DFmode],
-                                 REG_NOTES (pop_insn));
+  REG_NOTES (pop_insn)
+    = gen_rtx_EXPR_LIST (REG_DEAD, FP_MODE_REG (FIRST_STACK_REG, DFmode),
+                        REG_NOTES (pop_insn));
 
   regstack->reg[regstack->top - (hard_regno - FIRST_STACK_REG)]
     = regstack->reg[regstack->top];
@@ -1584,55 +1511,71 @@ 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_hard_swap_insn (insn, regstack, hard_regno, when)
+emit_swap_insn (insn, regstack, reg)
      rtx insn;
      stack regstack;
-     int hard_regno;
-     rtx (*when)();
+     rtx reg;
 {
-  rtx gen_swapdf();
+  int hard_regno;
   rtx swap_rtx, swap_insn;
-  int tmp, other;
+  int tmp, other_reg;          /* swap regno temps */
+  rtx i1;                      /* the stack-reg insn prior to INSN */
+  rtx i1set = NULL_RTX;                /* the SET rtx within I1 */
 
+  hard_regno = get_hard_regnum (regstack, reg);
+
+  if (hard_regno < FIRST_STACK_REG)
+    abort ();
   if (hard_regno == FIRST_STACK_REG)
     return;
 
-  swap_rtx = gen_swapdf (FP_mode_reg[hard_regno][(int) DFmode],
-                        FP_mode_reg[FIRST_STACK_REG][(int) DFmode]);
-  swap_insn = (*when) (swap_rtx, insn);
-  PUT_MODE (swap_insn, VOIDmode);
+  other_reg = regstack->top - (hard_regno - FIRST_STACK_REG);
 
-  other = regstack->top - (hard_regno - FIRST_STACK_REG);
-
-  tmp = regstack->reg[other];
-  regstack->reg[other] = regstack->reg[regstack->top];
+  tmp = regstack->reg[other_reg];
+  regstack->reg[other_reg] = regstack->reg[regstack->top];
   regstack->reg[regstack->top] = tmp;
-}
 
-/* Emit an insn before or after INSN to swap virtual register REG with the
-   top of stack.  See comments before emit_hard_swap_insn. */
+  /* Find the previous insn involving stack regs, but don't go past
+     any labels, calls or jumps.  */
+  i1 = prev_nonnote_insn (insn);
+  while (i1 && GET_CODE (i1) == INSN && !stack_regs_mentioned (i1))
+    i1 = prev_nonnote_insn (i1);
 
-static void
-emit_swap_insn (insn, regstack, reg, when)
-     rtx insn;
-     stack regstack;
-     rtx reg;
-     rtx (*when)();
-{
-  int hard_regno;
+  if (i1)
+    i1set = single_set (i1);
 
-  hard_regno = get_hard_regnum (regstack, reg);
-  if (hard_regno < FIRST_STACK_REG)
-    abort ();
+  if (i1set)
+    {
+      rtx i1src = *get_true_reg (&SET_SRC (i1set));
+      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.  */
 
-  emit_hard_swap_insn (insn, regstack, hard_regno, when);
+      if (GET_CODE (i1dest) == REG && REGNO (i1dest) == FIRST_STACK_REG
+         && GET_CODE (i1src) == REG && REGNO (i1src) == hard_regno - 1
+         && find_regno_note (i1, REG_DEAD, FIRST_STACK_REG) == NULL_RTX)
+       return;
+
+      /* If the previous insn wrote to the reg we are to swap with,
+        omit the swap.  */
+
+      if (GET_CODE (i1dest) == REG && REGNO (i1dest) == hard_regno
+         && GET_CODE (i1src) == REG && REGNO (i1src) == FIRST_STACK_REG
+         && find_regno_note (i1, REG_DEAD, FIRST_STACK_REG) == NULL_RTX)
+       return;
+    }
+
+  swap_rtx = gen_swapxf (FP_MODE_REG (hard_regno, XFmode),
+                        FP_MODE_REG (FIRST_STACK_REG, XFmode));
+  swap_insn = emit_insn_after (swap_rtx, i1);
 }
 \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)
@@ -1640,98 +1583,118 @@ 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_insn_before);
+      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 - 1)
+       {
+         /* A 387 cannot write an XFmode value to a MEM without
+            clobbering the source reg.  The output code can handle
+            this by reading back the value from the MEM.
+            But it is more efficient to use a temp register if one is
+            available.  Push the source value here if the register
+            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, XFmode);
+
+         push_rtx = gen_movxf (top_stack_reg, top_stack_reg);
+         push_insn = emit_insn_before (push_rtx, insn);
+         REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_DEAD, top_stack_reg,
+                                               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
@@ -1739,56 +1702,171 @@ 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
+/* Swap the condition on a branch, if there is one.  Return true if we
+   found a condition to swap.  False if the condition was not used as
+   such. */
+
+static int
+swap_rtx_condition_1 (pat)
+     rtx pat;
+{
+  register const char *fmt;
+  register int i, r = 0;
+
+  if (GET_RTX_CLASS (GET_CODE (pat)) == '<')
+    {
+      PUT_CODE (pat, swap_condition (GET_CODE (pat)));
+      r = 1;
+    }
+  else
+    {
+      fmt = GET_RTX_FORMAT (GET_CODE (pat));
+      for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
+       {
+         if (fmt[i] == 'E')
+           {
+             register int j;
+
+             for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
+               r |= swap_rtx_condition_1 (XVECEXP (pat, i, j));
+           }
+         else if (fmt[i] == 'e')
+           r |= swap_rtx_condition_1 (XEXP (pat, i));
+       }
+    }
+
+  return r;
+}
+
+static int
+swap_rtx_condition (insn)
+     rtx insn;
+{
+  rtx pat = PATTERN (insn);
+
+  /* We're looking for a single set to cc0 or an HImode temporary.  */
+
+  if (GET_CODE (pat) == SET
+      && GET_CODE (SET_DEST (pat)) == REG
+      && REGNO (SET_DEST (pat)) == FLAGS_REG)
+    {
+      insn = next_flags_user (insn);
+      if (insn == NULL_RTX)
+       return 0;
+      pat = PATTERN (insn);
+    }
+
+  /* See if this is, or ends in, a fnstsw, aka unspec 9.  If so, we're
+     not doing anything with the cc value right now.  We may be able to
+     search for one though.  */
+
+  if (GET_CODE (pat) == SET
+      && GET_CODE (SET_SRC (pat)) == UNSPEC
+      && XINT (SET_SRC (pat), 1) == 9)
+    {
+      rtx dest = SET_DEST (pat);
+
+      /* Search forward looking for the first use of this value. 
+        Stop at block boundaries.  */
+      /* ??? This really cries for BLOCK_END!  */
+      while (1)
+       {
+         insn = NEXT_INSN (insn);
+         if (insn == NULL_RTX)
+           return 0;
+         if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
+             && reg_mentioned_p (dest, insn))
+           break;
+         if (GET_CODE (insn) == JUMP_INSN)
+           return 0;
+         if (GET_CODE (insn) == CODE_LABEL)
+           return 0;
+       }
+
+      /* So we've found the insn using this value.  If it is anything
+        other than sahf, aka unspec 10, or the value does not die
+        (meaning we'd have to search further), then we must give up.  */
+      pat = PATTERN (insn);
+      if (GET_CODE (pat) != SET
+         || GET_CODE (SET_SRC (pat)) != UNSPEC
+         || XINT (SET_SRC (pat), 1) != 10
+         || ! dead_or_set_p (insn, dest))
+       return 0;
+
+      /* Now we are prepared to handle this as a normal cc0 setter.  */
+      insn = next_flags_user (insn);
+      if (insn == NULL_RTX)
+       return 0;
+      pat = PATTERN (insn);
+    }
+
+  return swap_rtx_condition_1 (pat);
+}
+
 /* Handle a comparison.  Special care needs to be taken to avoid
    causing comparisons that a 387 cannot do correctly, such as EQ.
 
    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)
+compare_for_stack_reg (insn, regstack, pat_src)
      rtx insn;
      stack regstack;
-     rtx pat;
+     rtx pat_src;
 {
   rtx *src1, *src2;
   rtx src1_note, src2_note;
+  rtx flags_user;
+
+  src1 = get_true_reg (&XEXP (pat_src, 0));
+  src2 = get_true_reg (&XEXP (pat_src, 1));
+  flags_user = next_flags_user (insn);
+
+  /* ??? If fxch turns out to be cheaper than fstp, give priority to
+     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))
+      && swap_rtx_condition (insn))
+    {
+      rtx temp;
+      temp = XEXP (pat_src, 0);
+      XEXP (pat_src, 0) = XEXP (pat_src, 1);
+      XEXP (pat_src, 1) = temp;
 
-  src1 = get_true_reg (&XEXP (SET_SRC (pat), 0));
-  src2 = get_true_reg (&XEXP (SET_SRC (pat), 1));
-
-  /* The first argument must always be a stack reg. */
-  /* ??? why? */
+      src1 = get_true_reg (&XEXP (pat_src, 0));
+      src2 = get_true_reg (&XEXP (pat_src, 1));
 
-  if (! STACK_REG_P (*src1))
-    abort ();
+      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));
 
   if (STACK_REG_P (*src2))
     src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
   else
-    src2_note = 0;
+    src2_note = NULL_RTX;
 
-  emit_swap_insn (insn, regstack, *src1, emit_insn_before);
+  emit_swap_insn (insn, regstack, *src1);
 
   replace_reg (src1, FIRST_STACK_REG);
 
@@ -1797,39 +1875,36 @@ compare_for_stack_reg (insn, regstack, pat)
 
   if (src1_note)
     {
-      CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (XEXP (src1_note, 0)));
+      pop_stack (regstack, REGNO (XEXP (src1_note, 0)));
       replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
-      regstack->top--;
     }
 
   /* 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)
+      && ! (STACK_REG_P (*src1) && STACK_REG_P (*src2)
            && REGNO (*src1) == REGNO (*src2)))
     {
       /* 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)
        {
-         CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (XEXP (src2_note, 0)));
+         pop_stack (regstack, REGNO (XEXP (src2_note, 0)));
          replace_reg (&XEXP (src2_note, 0), FIRST_STACK_REG + 1);
-         regstack->top--;
        }
       else
        {
          /* 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);
+         /* link_cc0_insns (insn); */
 
          remove_regno_note (insn, REG_DEAD, REGNO (XEXP (src2_note, 0)));
 
@@ -1840,7 +1915,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)
@@ -1849,16 +1924,18 @@ subst_stack_regs_pat (insn, regstack, pat)
      rtx pat;
 {
   rtx *dest, *src;
-  rtx *src1 = 0, *src2;
+  rtx *src1 = (rtx *) NULL_PTR, *src2;
   rtx src1_note, src2_note;
+  rtx pat_src;
 
   if (GET_CODE (pat) != SET)
     return;
 
   dest = get_true_reg (&SET_DEST (pat));
   src  = get_true_reg (&SET_SRC (pat));
+  pat_src = 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)
@@ -1867,27 +1944,35 @@ subst_stack_regs_pat (insn, regstack, pat)
                  || GET_CODE (*src) == CONST_DOUBLE))))
     move_for_stack_reg (insn, regstack, pat);
   else
-    switch (GET_CODE (SET_SRC (pat)))
+    switch (GET_CODE (pat_src))
       {
       case COMPARE:
-       compare_for_stack_reg (insn, regstack, pat);
+       compare_for_stack_reg (insn, regstack, pat_src);
        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:
       case ABS:
       case NEG:
@@ -1897,9 +1982,9 @@ subst_stack_regs_pat (insn, regstack, pat)
           source.  */
 
        if (src1 == 0)
-         src1 = get_true_reg (&XEXP (SET_SRC (pat), 0));
+         src1 = get_true_reg (&XEXP (pat_src, 0));
 
-       emit_swap_insn (insn, regstack, *src1, emit_insn_before);
+       emit_swap_insn (insn, regstack, *src1);
 
        src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
 
@@ -1921,42 +2006,38 @@ 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));
+       src1 = get_true_reg (&XEXP (pat_src, 0));
+       src2 = get_true_reg (&XEXP (pat_src, 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));
        else
-         src1_note = 0;
+         src1_note = NULL_RTX;
        if (STACK_REG_P (*src2))
          src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
        else
-         src2_note = 0;
+         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, emit_insn_before);
+         emit_swap_insn (insn, regstack, *dest);
        else
          {
            /* Both operands are REG.  If neither operand is already
               at the top of stack, choose to make the one that is the dest
-              the new top of stack.
-
-              ??? A later optimization here would be to look forward
-              in the insns and see which source reg will be needed at top
-              of stack soonest. */
+              the new top of stack.  */
 
            int src1_hard_regnum, src2_hard_regnum;
 
@@ -1967,7 +2048,7 @@ subst_stack_regs_pat (insn, regstack, pat)
 
            if (src1_hard_regnum != FIRST_STACK_REG
                && src2_hard_regnum != FIRST_STACK_REG)
-             emit_swap_insn (insn, regstack, *dest, emit_insn_before);
+             emit_swap_insn (insn, regstack, *dest);
          }
 
        if (STACK_REG_P (*src1))
@@ -1981,7 +2062,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])
              {
@@ -2035,6 +2116,123 @@ subst_stack_regs_pat (insn, regstack, pat)
 
        break;
 
+      case UNSPEC:
+       switch (XINT (pat_src, 1))
+         {
+         case 1: /* sin */
+         case 2: /* cos */
+           /* These insns only operate on the top of the stack.  */
+
+           src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
+
+           emit_swap_insn (insn, regstack, *src1);
+
+           src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
+
+           if (STACK_REG_P (*dest))
+             replace_reg (dest, FIRST_STACK_REG);
+
+           if (src1_note)
+             {
+               replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
+               regstack->top--;
+               CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (*src1));
+             }
+
+           replace_reg (src1, FIRST_STACK_REG);
+
+           break;
+
+         case 10:
+           /* (unspec [(unspec [(compare ..)] 9)] 10)
+              Unspec 9 is fnstsw; unspec 10 is sahf.  The combination
+              matches the PPRO fcomi instruction.  */
+
+           pat_src = XVECEXP (pat_src, 0, 0);
+           if (GET_CODE (pat_src) != UNSPEC
+               || XINT (pat_src, 1) != 9)
+             abort ();
+           /* FALLTHRU */
+
+         case 9:
+           /* (unspec [(compare ..)] 9)
+              Combined fcomp+fnstsw generated for doing well with CSE.
+              When optimizing this would have been broken up before now.  */
+
+           pat_src = XVECEXP (pat_src, 0, 0);
+           if (GET_CODE (pat_src) != COMPARE)
+             abort ();
+
+           compare_for_stack_reg (insn, regstack, pat_src);
+           break;
+
+         default:
+           abort ();
+         }
+       break;
+
+      case IF_THEN_ELSE:
+       /* This insn requires the top of stack to be the destination. */
+
+       /* If the comparison operator is an FP comparison operator,
+          it is handled correctly by compare_for_stack_reg () who
+          will move the destination to the top of stack. But if the
+          comparison operator is not an FP comparison operator, we
+          have to handle it here. */
+       if (get_hard_regnum (regstack, *dest) >= FIRST_STACK_REG
+           && REGNO (*dest) != regstack->reg[regstack->top])
+         emit_swap_insn (insn, regstack, *dest);       
+
+       src1 = get_true_reg (&XEXP (pat_src, 1));
+       src2 = get_true_reg (&XEXP (pat_src, 2));
+
+       src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
+       src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
+
+       {
+         rtx src_note [3];
+         int i;
+
+         src_note[0] = 0;
+         src_note[1] = src1_note;
+         src_note[2] = src2_note;
+
+         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])
+             {
+               /* 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--;
+                 }
+             }
+       }
+
+       /* Make dest the top of stack.  Add dest to regstack if not present. */
+       if (get_hard_regnum (regstack, *dest) < FIRST_STACK_REG)
+         regstack->reg[++regstack->top] = REGNO (*dest);       
+       SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
+       replace_reg (dest, FIRST_STACK_REG);
+
+       break;
+
       default:
        abort ();
       }
@@ -2042,12 +2240,7 @@ subst_stack_regs_pat (insn, regstack, pat)
 \f
 /* Substitute hard regnums for any stack regs in INSN, which has
    N_INPUTS inputs and N_OUTPUTS outputs.  REGSTACK is the stack info
-   before the insn, and is updated with changes made here.  CONSTRAINTS is
-   an array of the constraint strings used in the asm statement.
-
-   OPERANDS is an array of the operands, and OPERANDS_LOC is a
-   parallel array of where the operands were found.  The output operands
-   all precede the input operands.
+   before the insn, and is updated with changes made here.
 
    There are several requirements and assumptions about the use of
    stack-like regs in asm statements.  These rules are enforced by
@@ -2056,21 +2249,12 @@ subst_stack_regs_pat (insn, regstack, pat)
    requirements, since record_asm_stack_regs removes any problem asm.  */
 
 static void
-subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
-                     n_inputs, n_outputs)
+subst_asm_stack_regs (insn, regstack)
      rtx insn;
      stack regstack;
-     rtx *operands, **operands_loc;
-     char **constraints;
-     int n_inputs, n_outputs;
 {
-  int n_operands = n_inputs + n_outputs;
-  int first_input = n_outputs;
   rtx body = PATTERN (insn);
-
-  int *operand_matches = (int *) alloca (n_operands * sizeof (int *));
-  enum reg_class *operand_class 
-    = (enum reg_class *) alloca (n_operands * sizeof (enum reg_class *));
+  int alt;
 
   rtx *note_reg;               /* Array of note contents */
   rtx **note_loc;              /* Address of REG field of each note */
@@ -2084,24 +2268,31 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
   int n_clobbers;
   rtx note;
   int i;
+  int n_inputs, n_outputs;
 
   /* 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).  */
+  extract_insn (insn);
+  constrain_operands (1);
+  alt = which_alternative;
+
+  preprocess_constraints ();
 
-  i = constrain_asm_operands (n_operands, operands, constraints,
-                             operand_matches, operand_class);
-  if (i < 0)
+  n_inputs = get_asm_operand_n_inputs (body);
+  n_outputs = recog_data.n_operands - n_inputs;
+  
+  if (alt < 0)
     abort ();
 
-  /* 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)
+  /* Strip SUBREGs here to make the following code simpler.  */
+  for (i = 0; i < recog_data.n_operands; i++)
+    if (GET_CODE (recog_data.operand[i]) == SUBREG
+       && GET_CODE (SUBREG_REG (recog_data.operand[i])) == REG)
       {
-       operands_loc[i] = & SUBREG_REG (operands[i]);
-       operands[i] = SUBREG_REG (operands[i]);
+       recog_data.operand_loc[i] = & SUBREG_REG (recog_data.operand[i]);
+       recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
       }
 
   /* Set up NOTE_REG, NOTE_LOC and NOTE_KIND.  */
@@ -2142,8 +2333,8 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
 
   if (GET_CODE (body) == PARALLEL)
     {
-      clobber_reg = (rtx *) alloca (XVECLEN (body, 0) * sizeof (rtx *));
-      clobber_loc = (rtx **) alloca (XVECLEN (body, 0) * sizeof (rtx **));
+      clobber_reg = (rtx *) alloca (XVECLEN (body, 0) * sizeof (rtx));
+      clobber_loc = (rtx **) alloca (XVECLEN (body, 0) * sizeof (rtx *));
 
       for (i = 0; i < XVECLEN (body, 0); i++)
        if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
@@ -2167,38 +2358,39 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
          }
     }
 
-  bcopy (regstack, &temp_stack, sizeof (temp_stack));
+  bcopy ((char *) regstack, (char *) &temp_stack, sizeof (temp_stack));
 
   /* Put the input regs into the desired place in TEMP_STACK.  */
 
-  for (i = first_input; i < first_input + n_inputs; i++)
-    if (STACK_REG_P (operands[i])
-       && reg_class_subset_p (operand_class[i], FLOAT_REGS)
-       && operand_class[i] != FLOAT_REGS)
+  for (i = n_outputs; i < n_outputs + n_inputs; i++)
+    if (STACK_REG_P (recog_data.operand[i])
+       && reg_class_subset_p (recog_op_alt[i][alt].class,
+                              FLOAT_REGS)
+       && recog_op_alt[i][alt].class != FLOAT_REGS)
       {
        /* If an operand needs to be in a particular reg in
           FLOAT_REGS, the constraint was either 't' or 'u'.  Since
-          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. */
+          these constraints are for single register classes, and
+          reload guaranteed that operand[i] is already in that class,
+          we can just use REGNO (recog_data.operand[i]) to know which
+          actual reg this operand needs to be in.  */
 
-       int regno = get_hard_regnum (&temp_stack, operands[i]);
+       int regno = get_hard_regnum (&temp_stack, recog_data.operand[i]);
 
        if (regno < 0)
          abort ();
 
-       if (regno != REGNO (operands[i]))
+       if (regno != REGNO (recog_data.operand[i]))
          {
-           /* 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. */
+           /* recog_data.operand[i] is not in the right place.  Find
+              it and swap it with whatever is already in I's place.
+              K is where recog_data.operand[i] is now.  J is where it
+              should be.  */
            int j, k, temp;
 
            k = temp_stack.top - (regno - FIRST_STACK_REG);
            j = (temp_stack.top
-                - (REGNO (operands[i]) - FIRST_STACK_REG));
+                - (REGNO (recog_data.operand[i]) - FIRST_STACK_REG));
 
            temp = temp_stack.reg[k];
            temp_stack.reg[k] = temp_stack.reg[j];
@@ -2212,17 +2404,17 @@ 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]))
+  for (i = n_outputs; i < n_outputs + n_inputs; i++)
+    if (STACK_REG_P (recog_data.operand[i]))
       {
-       int regnum = get_hard_regnum (regstack, operands[i]);
+       int regnum = get_hard_regnum (regstack, recog_data.operand[i]);
 
        if (regnum < 0)
          abort ();
 
-       replace_reg (operands_loc[i], regnum);
+       replace_reg (recog_data.operand_loc[i], regnum);
       }
 
   for (i = 0; i < n_notes; i++)
@@ -2248,30 +2440,30 @@ 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]))
+  for (i = n_outputs; i < n_outputs + n_inputs; i++)
+    if (STACK_REG_P (recog_data.operand[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++)
-         if (operands_match_p (clobber_reg[j], operands[i]))
+         if (operands_match_p (clobber_reg[j], recog_data.operand[i]))
            break;
 
-       if (j < n_clobbers || operand_matches[i] >= 0)
+       if (j < n_clobbers || recog_op_alt[i][alt].matches >= 0)
          {
-           /* operands[i] might not be at the top of stack.  But that's OK,
-              because all we need to do is pop the right number of regs
-              off of the top of the reg-stack.  record_asm_stack_regs
-              guaranteed that all implicitly popped regs were grouped
-              at the top of the reg-stack.  */
+           /* recog_data.operand[i] might not be at the top of stack.
+              But that's OK, because all we need to do is pop the
+              right number of regs off of the top of the reg-stack.
+              record_asm_stack_regs guaranteed that all implicitly
+              popped regs were grouped at the top of the reg-stack.  */
 
            CLEAR_HARD_REG_BIT (regstack->reg_set,
                                regstack->reg[regstack->top]);
@@ -2281,7 +2473,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--)
     {
@@ -2289,7 +2481,8 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
       int j;
 
       for (j = 0; j < n_outputs; j++)
-       if (STACK_REG_P (operands[j]) && REGNO (operands[j]) == i)
+       if (STACK_REG_P (recog_data.operand[j])
+           && REGNO (recog_data.operand[j]) == i)
          {
            regstack->reg[++regstack->top] = i;
            SET_HARD_REG_BIT (regstack->reg_set, i);
@@ -2305,31 +2498,32 @@ subst_asm_stack_regs (insn, regstack, operands, operands_loc, constraints,
      in the death notes have already been substituted.  */
 
   for (i = 0; i < n_outputs; i++)
-    if (STACK_REG_P (operands[i]))
+    if (STACK_REG_P (recog_data.operand[i]))
       {
        int j;
 
        for (j = 0; j < n_notes; j++)
-         if (REGNO (operands[i]) == REGNO (note_reg[j])
+         if (REGNO (recog_data.operand[i]) == REGNO (note_reg[j])
              && note_kind[j] == REG_UNUSED)
            {
-             insn = emit_pop_insn (insn, regstack, operands[i],
+             insn = emit_pop_insn (insn, regstack, recog_data.operand[i],
                                    emit_insn_after);
              break;
            }
       }
 
-  for (i = first_input; i < first_input + n_inputs; i++)
-    if (STACK_REG_P (operands[i]))
+  for (i = n_outputs; i < n_outputs + n_inputs; i++)
+    if (STACK_REG_P (recog_data.operand[i]))
       {
        int j;
 
        for (j = 0; j < n_notes; j++)
-         if (REGNO (operands[i]) == REGNO (note_reg[j])
+         if (REGNO (recog_data.operand[i]) == REGNO (note_reg[j])
              && note_kind[j] == REG_DEAD
-             && TEST_HARD_REG_BIT (regstack->reg_set, REGNO (operands[i])))
+             && TEST_HARD_REG_BIT (regstack->reg_set,
+                                   REGNO (recog_data.operand[i])))
            {
-             insn = emit_pop_insn (insn, regstack, operands[i],
+             insn = emit_pop_insn (insn, regstack, recog_data.operand[i],
                                    emit_insn_after);
              break;
            }
@@ -2339,7 +2533,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)
@@ -2348,50 +2542,50 @@ subst_stack_regs (insn, regstack)
 {
   register rtx *note_link, note;
   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)
+  if (stack_regs_mentioned (insn))
     {
-      n_operands = asm_noperands (PATTERN (insn));
+      int 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 do register substitution.
-            Any REG_UNUSED notes will be handled by subst_asm_stack_regs. */
-
-         rtx operands[MAX_RECOG_OPERANDS];
-         rtx *operands_loc[MAX_RECOG_OPERANDS];
-         rtx body = PATTERN (insn);
-         int n_inputs, n_outputs;
-         char **constraints
-           = (char **) alloca (n_operands * sizeof (char *));
-
-         decode_asm_operands (body, operands, operands_loc, constraints, 0);
-         get_asm_operand_lengths (body, n_operands, &n_inputs, &n_outputs);
-         subst_asm_stack_regs (insn, regstack, operands, operands_loc,
-                               constraints, n_inputs, n_outputs);
+            Any REG_UNUSED notes will be handled by subst_asm_stack_regs.  */
+
+         subst_asm_stack_regs (insn, regstack);
          return;
        }
 
       if (GET_CODE (PATTERN (insn)) == PARALLEL)
-       for (i = 0; i < XVECLEN (PATTERN (insn) , 0); i++)
+       for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
          {
            if (stack_regs_mentioned_p (XVECEXP (PATTERN (insn), 0, i)))
              subst_stack_regs_pat (insn, regstack,
@@ -2402,15 +2596,15 @@ 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 (INSN_DELETED_P (insn))
+  if (GET_CODE (insn) == NOTE)
     return;
 
   /* 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))
@@ -2433,7 +2627,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)
@@ -2451,17 +2645,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));
@@ -2469,10 +2663,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);
 
@@ -2483,47 +2677,48 @@ change_stack (insn, old, new, when)
       if (old->top != new->top)
        abort ();
 
-      /* Loop here emitting swaps until the stack is correct.  The
-        worst case number of swaps emitted is N + 2, where N is the
+      /* If the stack is not empty (new->top != -1), loop here emitting
+        swaps until the stack is correct. 
+
+        The worst case number of swaps emitted is N + 2, where N is the
         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. */
+      if (new->top != -1)
+       do
+         {
+           /* Swap the reg at top of stack into the position it is
+              supposed to be in, until the correct top of stack appears.  */
 
-         while (old->reg[old->top] != new->reg[new->top])
-           {
-             for (reg = new->top; reg >= 0; reg--)
-               if (new->reg[reg] == old->reg[old->top])
-                 break;
+           while (old->reg[old->top] != new->reg[new->top])
+             {
+               for (reg = new->top; reg >= 0; reg--)
+                 if (new->reg[reg] == old->reg[old->top])
+                   break;
 
-             if (reg == -1)
-               abort ();
+               if (reg == -1)
+                 abort ();
 
-             emit_swap_insn (insn, old,
-                             FP_mode_reg[old->reg[reg]][(int) DFmode],
-                             emit_insn_before);
-           }
+               emit_swap_insn (insn, old,
+                               FP_MODE_REG (old->reg[reg], DFmode));
+             }
 
-         /* See if any regs remain incorrect.  If so, bring an
+           /* 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],
-                               emit_insn_before);
-               break;
-             }
-       } while (reg >= 0);
+           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], 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])
@@ -2539,7 +2734,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)
@@ -2554,34 +2749,43 @@ goto_block_pat (insn, regstack, pat)
   struct stack_def temp_stack;
   int reg;
 
-  if (GET_CODE (pat) != LABEL_REF)
+  switch (GET_CODE (pat))
     {
-      int i, j;
-      char *fmt = GET_RTX_FORMAT (GET_CODE (pat));
-
-      for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
-       {
-         if (fmt[i] == 'e')
-           goto_block_pat (insn, regstack, XEXP (pat, i));
-         if (fmt[i] == 'E')
-           for (j = 0; j < XVECLEN (pat, i); j++)
-             goto_block_pat (insn, regstack, XVECEXP (pat, i, j));
-       }
+    case RETURN:
+      straighten_stack (PREV_INSN (insn), regstack);
       return;
+    default:
+      {
+       int i, j;
+       const char *fmt = GET_RTX_FORMAT (GET_CODE (pat));
+
+       for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
+         {
+           if (fmt[i] == 'e')
+             goto_block_pat (insn, regstack, XEXP (pat, i));
+           if (fmt[i] == 'E')
+             for (j = 0; j < XVECLEN (pat, i); j++)
+               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;
 
   label_stack = &block_stack_in[BLOCK_NUM (label)];
 
   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]))
@@ -2589,7 +2793,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;
@@ -2609,7 +2813,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));
@@ -2622,7 +2826,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)
@@ -2639,7 +2843,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;
 
@@ -2648,7 +2852,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 ()
@@ -2673,7 +2877,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];
@@ -2683,17 +2887,27 @@ 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)
+         if (stack_regs_mentioned (insn) || GET_CODE (insn) == CALL_INSN)
            subst_stack_regs (insn, &regstack);
 
        } while (insn != block_end[block]);
+      
+      /* For all further actions, INSN needs to be the last insn in
+         this basic block.  If subst_stack_regs inserted additional
+         instructions after INSN, it is no longer the last one at
+         this point.  */
+      next = PREV_INSN (next);
+
+      /* If subst_stack_regs inserted something after a JUMP_INSN, that
+         is almost certainly a bug.  */
+      if (GET_CODE (insn) == JUMP_INSN && insn != next)
+       abort ();
+      insn = next;
 
-      /* 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);
 
@@ -2704,12 +2918,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],
@@ -2718,18 +2932,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. */
-
-  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],
-                           emit_insn_after);
+     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 (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)
@@ -2738,7 +2967,7 @@ print_blocks (file, insn, pat)
 {
   register RTX_CODE code = GET_CODE (pat);
   register int i;
-  register char *fmt;
+  register const char *fmt;
 
   if (code == LABEL_REF)
     {
@@ -2768,6 +2997,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;
@@ -2799,14 +3029,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);
This page took 0.131521 seconds and 5 git commands to generate.