This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc optimisation bug


Alan Modra <alan@SPRI.Levels.UniSA.Edu.Au> writes:

> On Mon, 17 Jan 2000, Erik Sandberg wrote:
> 
> > I have found a GCC bug.
> 
> Same results under x86 gcc-20000114.  Here's an addition to the testsuite
> for somebody to commit.  I don't have write access.

Here's a smaller test case:

typedef struct card
{   
  struct card *next;
} card;

card cards[4];

int main(void)
{   
  int i, j;
  card *c = (card *)0;

 for (i = 0; i < 4; i++)
      {     
        cards[i].next = c;
        c = &cards[i];
      }
        
  if (cards[0].next != 0)
        abort();
 
  exit(0);
}


and here's the patch to fix it.  When checking to see if a loop is
reversible, we check to make sure that any mem stores don't depend on an
initial value.  However, we were only checking that registers in the MEM
itself were ok.  But if any part of the store (in this case the SET_SRC)
depends on an initial value, the loop is irreversible.

Is this ok?

2000-01-18  Clinton Popetz  <cpopetz@cygnus.com>

	* loop.c (check_dbra_loop): When checking a loop for
	reversability, check the source of any stores to ensure they 
	don't depend on an initial value.


Index: loop.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/loop.c,v
retrieving revision 1.217
diff -c -2 -p -r1.217 loop.c
*** loop.c	2000/01/15 03:01:49	1.217
--- loop.c	2000/01/18 06:53:21
*************** check_dbra_loop (loop, insn_count)
*** 8035,8039 ****
  		  if (v->giv_type == DEST_REG
  		      && reg_mentioned_p (v->dest_reg,
! 					  XEXP (loop_store_mems, 0))
  		      && loop_insn_first_p (first_loop_store_insn, v->insn))
  		    reversible_mem_store = 0;
--- 8035,8039 ----
  		  if (v->giv_type == DEST_REG
  		      && reg_mentioned_p (v->dest_reg,
! 					 PATTERN (first_loop_store_insn)) 
  		      && loop_insn_first_p (first_loop_store_insn, v->insn))
  		    reversible_mem_store = 0;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]