home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:13170 comp.sys.sun.misc:4067
- Path: sparky!uunet!metrix!ama
- From: ama@metrix.UUCP (Alan Amaral)
- Newsgroups: comp.lang.c,comp.sys.sun.misc
- Subject: Re: sun cc optimization failure
- Message-ID: <881@metrix.UUCP>
- Date: 3 Sep 92 15:08:05 GMT
- References: <1992Sep3.040401.16902@mr.med.ge.com>
- Reply-To: ama@metrix.UUCP (Alan Amaral)
- Organization: Matrix Computer Systems Inc.
- Lines: 33
-
- In article <1992Sep3.040401.16902@mr.med.ge.com> carl@aslmr-serv.med.ge.com (Carl Crawford) writes:
- >
- >consider the following program:
- >
- >main() {
- > int i,j,ax;
- > ax = 0;
- > for(i=0;i<3;i++){
- > j = ax * i;
- > puts("in for loop");
- > }
- >}
-
- By the way, if you change the ax=0 to ax=1 the problem goes away. It also
- goes away if you remove the j = ax * i; from the loop. Apparently the
- global opimizer, in trying to remove the invariant expression from the loop
- (j == 0 ALWAYS if ax == 0), apparently screws up the loop variable
- initialization (as I explained in my last message) which causes the code not
- to loop at all.
-
- Adding more code to the loop, say k = ay * i; where ay = 1; will also fix
- the problem. Strangely enough the assembler code is IDENTICAL (except for
- the register initialization being correct) if you add the extra code, as k
- is not used in the loop, so the calculation is totally eliminated. The
- compiler apparently doesn't screw up the initialization in this case...
-
- It looks like the compiler has problems with removing invariant expressions,
- but not unused expressions...
-
- Curiouser and curiouser...
- --
- Alan Amaral | Email: ama@metrix.COM
- Metrix Network Systems | Voice: (603) 888-7000
-