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]

one example of insufficient optimization


The egcs version 1.0.2 on Sparc platform (under Solaris 2.6) compiles
(with -O3, inlining allowed) this:


class iterator {
...

   friend bool operator!= (const iterator& it1, const iterator& it2)
   {  return it1.ptr1!=it2.ptr1 || it1.ptr2!=it2.ptr2; }
   // ptr1 and ptr2 are some data members of a pointer type
};

iterator nb, end;
while (nb!=end) {
   ...
}


to the following machine code:

0x14f88 <main+4152>:	ld  [ %fp + -192 ], %o2    ! nb.ptr1
0x14f8c <main+4156>:	ld  [ %fp + -160 ], %o0    ! end.ptr1
0x14f90 <main+4160>:	cmp  %o2, %o0
0x14f94 <main+4164>:	bne  0x14fb0 <main+4192>
0x14f98 <main+4168>:	clr  %o1
0x14f9c <main+4172>:	ld  [ %fp + -200 ], %o1    ! nb.ptr2
0x14fa0 <main+4176>:	ld  [ %fp + -168 ], %o0    ! end.ptr2
0x14fa4 <main+4180>:	xor  %o1, %o0, %o1
0x14fa8 <main+4184>:	cmp  %g0, %o1
0x14fac <main+4188>:	subx  %g0, -1, %o1
0x14fb0 <main+4192>:	cmp  %o1, 0
0x14fb4 <main+4196>:	bne  0x15a64 <main+6932>


which has two defects:

1) the jump at main+4164 was not redirected to the final target main+6932
   as it should be, if -fthread-jumps had kept its promise. Is this
   optimizer phase not repeated after the insertion of inline functions?

2) the result of the comparison is forced into the boolean value domain at the
   price of three extra instructions, where a single cmp would do. Would it be
   possible to eliminate this overhead in the cases where it's clear that the
   boolean is to be evaluated ONCE in a branch?

Perhaps I want too much... But such expressions occurs very often in loops, so,
I think, additional compilation time would be amortized by the expected
acceleration of the programs.


With best regards,
Ewgenij Gawrilow,
Technical University Berlin


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