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]
Other format: [Raw text]

[Bug other/16799] New: PowerPC - load reuse opportunity


Description:
A non-optimal code sequence is illustrated.  There exists an opportunity to reuse a value loaded in a loop and avoid reloading it on a subsequent iteration of the loop.  Duplicate using gcc 3.5 and command line:

gcc -O3 -m64 -c test.c

Testcase:
typedef struct {
    unsigned int e;
} str;
char *q;

void foo (char *p) {

  while (1) {
    q = p - ((str *)p)->e;
    if (((str *)q)->e) break;
    p = q;
  }

}

Assembly:
 On entry to the loop body, the first "lwz 0,0(9)" is reloading the value already loaded into gpr0 by the peeled iteration of the loop.  On subsequent iterations of the loop, the value has already been loaded by the second lwz on the previous iteration.  Thus, the first lwz is unnecessary.

.foo:
	lwz 0,0(3)
	ld 11,.LC0@toc(2)
	subf 3,0,3
	std 3,0(11)
	lwz 0,0(3)
	cmpwi 7,0,0
	bnelr- 7
	mr 9,3
.L4:
	lwz 0,0(9)  <-- Unnecessary, value is already in gpr 0.
	subf 9,0,9
	std 9,0(11)
	lwz 0,0(9)
	cmpwi 7,0,0
	beq+ 7,.L4
	blr



-- 
           Summary: PowerPC - load reuse opportunity
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P1
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: steinmtz at us dot ibm dot com
                CC: gcc-bugs at gcc dot gnu dot org,steinmtz at us dot ibm
                    dot com
 GCC build triplet: powerpc64-linux
  GCC host triplet: powerpc64-linux
GCC target triplet: powerpc64-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16799


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