strength reduction tweek

Jan Hubicka jh@suse.cz
Tue Aug 7 11:46:00 GMT 2001


Hi,
I am experimenting with following loop:

float a[100][8];
float b[100][8];
main()
{
   int y,i;
   for (y=0;y<100000;y++)
   for (i=0;i<100;i++)
	{
	  a[i][0]=b[i][0]+1;
	  a[i][1]=b[i][1]+1;
	  a[i][2]=b[i][2]+1;
	  a[i][3]=b[i][3]+1;
	  a[i][4]=b[i][4]+1;
	  a[i][5]=b[i][5]+1;
	  a[i][6]=b[i][6]+1;
	  a[i][7]=b[i][7]+1;
	}
}

interestingly enought, gcc decides to not use i386 addressing modes and
instead computes i*32+constant to register and then adds it in each
instruction.

The problem is that cost in strength_reduction is computed somewhat
inexactly.  if we estimate cost of address reducing giv, we compute cost of
replacing it by register.  I386 cost macro contains code to reduce
register pressure and prefferes complex address, so the cost is negative.

Later we manage to combine givs and we are about to replace the giv
by even more complex addressing mode, but we don't recompute the benefit
(that should be now possitive - it is zero, but I am sending separate
patch for this shortly).

Honza

Tue Aug  7 20:24:09 CEST 2001  Jan Hubicka  <jh@suse.cz>
	* loop.c (combine_givs): Fix computing of benefit once giv is combined.

Index: gcc/loop.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/loop.c,v
retrieving revision 1.342
diff -c -3 -p -r1.342 loop.c
*** loop.c	2001/08/04 12:08:42	1.342
--- loop.c	2001/08/07 18:36:22
*************** restart:
*** 6844,6849 ****
--- 6844,6856 ----
  
  	      g2->new_reg = can_combine[i * giv_count + j];
  	      g2->same = g1;
+ 	      /* For destination, we now may replace by mem expression instead
+ 		 of register.  This changes the costs considerably, so add the
+ 		 compensation.  */
+ 	      if (g2->giv_type == DEST_ADDR)
+ 		g2->benefit = (g2->benefit + reg_address_cost
+ 			       - address_cost (g2->new_reg,
+ 			       GET_MODE (g2->mem)));
  	      g1->combined_with++;
  	      g1->lifetime += g2->lifetime;
  



More information about the Gcc-patches mailing list