gcc4.5 ivopts question.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear folks,

I have question about ivopts.

I'm currently implementing gcc on microchip embedded processor
pic18f. Gcc version 4.5 is obtained from svn trunk.

When a C source program uses pointer auto increment operator within a
loop, sometimes ivopts replaces a pointer reference to an indexed memory access,
which causes poor performance in my case. The detail description
attached bellow.  Does somebody give me a suggestion?



When compiling the following simple strcpy program,
gcc can generate not optimal code with -O.

------------------------
char *strcp(char *d, char *s) {
	char *t = *d;
	while ((*d++ = *s++));
	return t;
}
------------------------

The strcpy.138r.expand dump shows that the program is translated to
the following codes:

------------------------
;; Function strcp (strcp)
strcp (char * d, char * s)
{
  unsigned int ivtmp.7;
  char D.1990;

  # BLOCK 2 freq:1400
  # PRED: ENTRY [100.0%]  (fallthru,exec)
  ivtmp.7_16 = (unsigned int) s_5(D);
  # SUCC: 3 [100.0%]  (fallthru,exec)

  # BLOCK 3 freq:10000
  # PRED: 2 [100.0%]  (fallthru,exec) 3 [86.0%]  (true,exec)
  # d_2 = PHI <d_3(D)(2), d_9(3)>
  # ivtmp.7_7 = PHI <ivtmp.7_16(2), ivtmp.7_15(3)>
  D.1990_6 = MEM[index: ivtmp.7_7];
  ivtmp.7_15 = ivtmp.7_7 + 1;
  MEM[base: d_2] = D.1990_6;
  d_9 = d_2 + 1;
  if (D.1990_6 != 0)
    goto <bb 3>;
  else
    goto <bb 4>;
  # SUCC: 3 [86.0%]  (true,exec) 4 [14.0%]  (false,exec)

  # BLOCK 4 freq:1400
  # PRED: 3 [14.0%]  (false,exec)
  return d_3(D);
  # SUCC: EXIT [100.0%]

}
------------------------

In the pic18f architecture, only three special registers can achieve
indirect memory accesses, One is used for a stack ptr, other two
registers can be used for user code.  Those registers have auto
incr/decr functions and can hold 12bit data.  That is enough for
entire RAM space(4096B), but not enough for holding integer(16bit).

Without the ivopts optimization, "src" and "dst" variables are
successfully allocated on the indirect addressing registers, the code
is excellent, the loop consists from 3 instructinos: source read,
destination write, conditional jump.

But when ivopts is enabled, the following part of above gimple code
causes the problem.

  unsigned int ivtmp.7;

  D.1990_6 = MEM[index: ivtmp.7_7];
  ivtmp.7_15 = ivtmp.7_7 + 1;
  MEM[base: d_2] = D.1990_6;

In this case, the "src" register will be allocated to normal integer
register (ivtmp), the variable is introduced by ivopt. Because of this
register allocation, every memory access requires register transfer
from integer to pointer and normal register increment, resulting
slower loop.

Did I do something wrong or is there any mean to improve the code?



The compiler version information as follows:

% svn info
Path: .
URL: svn://gcc.gnu.org/svn/gcc/trunk
Repository Root: svn://gcc.gnu.org/svn/gcc
Repository UUID: 138bc75d-0d04-0410-961f-82ee72b054a4
Revision: 152424
Node Kind: directory
Schedule: normal
Last Changed Author: ccoutant
Last Changed Rev: 152421
Last Changed Date: 2009-10-03 05:44:09 +0900 (Sat, 03 Oct 2009)

Thanks in advance.

K.K

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux