[PATCH] Fix -fcompare-debug failures caused by combine-stack-adj pass

Eric Botcazou ebotcazou@adacore.com
Sun Sep 6 10:45:00 GMT 2009


> On the attached testcase on i586 csa pass fails to merge two stack
> adjustments if there is a DEBUG_INSN with (mem (mem (sp + cst)) in it.

I presume you meant "between them".

> While that testcase can be fixed just by the first record_stack_memrefs
> hunk, I'm pretty sure it is possible to have a sp reference in DEBUG_INSN
> that CSA doesn't handle ATM, which would still lead to -fcompare-debug
> failure, as with -g adjustments wouldn't be merged because of it, while
> with -g0 when there is no such DEBUG_INSN they would.
> Fortunately in DEBUG_INSN we can just replace SP with SP + CST as a
> fallback.

Thanks for working on this.

> 2009-09-04  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR bootstrap/41241
> 	* combine-stack-adj.c (record_one_stack_memref): Handle REG_P.
> 	(try_apply_stack_adjustment): Likewise.
> 	(record_stack_memrefs): For DEBUG_INSNs keep traversing subexpressions
> 	instead of failing when a MEM contains SP references.  For SP itself
> 	in DEBUG_INSNs queue it also onto memlist chain.

OK on principle, but the names and comments would need to be updated, in 
particular:

/* This structure records stack memory references between stack adjusting
   instructions.  */

struct csa_memlist
{
  HOST_WIDE_INT sp_offset;
  rtx insn, *mem;
  struct csa_memlist *next;
};

/* This structure records two kinds of stack references between stack
   adjusting instructions: stack references in memory addresses for
   regular insns and all stack references for debug insns.  */

struct csa_reflist
{
  HOST_WIDE_INT sp_offset;
  rtx insn, *ref;
  struct csa_reflist *next;
};


/* Create a new csa_memlist node from the given memory reference.
   It is already known that the memory is stack_memref_p.  */

static struct csa_memlist *
record_one_stack_memref (rtx insn, rtx *mem, struct csa_memlist *next_memlist)
{
  struct csa_memlist *ml;

  ml = XNEW (struct csa_memlist);

  if (REG_P (*mem) || XEXP (*mem, 0) == stack_pointer_rtx)
    ml->sp_offset = 0;
  else
    ml->sp_offset = INTVAL (XEXP (XEXP (*mem, 0), 1));

  ml->insn = insn;
  ml->mem = mem;
  ml->next = next_memlist;

  return ml;
}

/* Create a new csa_reflist node from the given stack reference.
   It is already known that the reference is either a MEM satisfying the
   predicate stack_memref_p or a REG representing the stack pointer.  */

static struct csa_reflist *
record_one_stack_ref (rtx insn, rtx *ref, struct csa_reflist *next_reflist)
{
  struct csa_reflist *ml;

  ml = XNEW (struct csa_reflist);

  if (REG_P (*ref) || REG_P (XEXP (*ref, 0)))
    ml->sp_offset = 0;
  else
    ml->sp_offset = INTVAL (XEXP (XEXP (*ref, 0), 1));

  ml->insn = insn;
  ml->ref = ref;
  ml->next = next_reflist;

  return ml;
}

and so on.


Please also fix the formatting of the 2nd line of try_apply_stack_adjustment.

-- 
Eric Botcazou



More information about the Gcc-patches mailing list