[comp.lang.c] '386 XENIX "cc -Ox" optimization bug

jon@ccwf.cc.utexas.edu (Jon Boede) (12/08/90)

Hopefully I'm posting old news... but I found a rather insidious bug in cc
version 1.6.  It seems that if you use the -Oa "ignore aliasing" option with
the -Ol "enable loop optimizations" option, it starts thinking deciding that
more things are loop invariants than really are!  The seductively named -Ox
"max. optimization" option implies -Oal.

Try: cc x.c; a.out; cc -Ox x.c; a.out; cc -Oal x.c; a.out

----- cut here -- x.c
main()
{
	int value;

	value = 1;
	printf("1. value is %d\n",value);

	do {
		printf("2. value is %d\n",value);
		puts(value ? "works ok" : "your compiler is broke");
		value = 0;
	} while (false());
}

false()
{
	return(0);
}
----- ereh tuc

It's a little bothersome to turn on "max. optimization" and have your code stop
working! ;-)

Jon
-- 
Jon Boede    jon@bodedo.ucm.org  ...!{the-world}!uunet!cs.utexas.edu!bodedo!jon
7117 Wood Hollow #1013, People's Republic of Austin, TX  78731  +1 512 346-3142

davidsen@sixhub.UUCP (Wm E. Davidsen Jr) (12/09/90)

In article <40991@ut-emx.uucp> jon@ccwf.cc.utexas.edu (Jon Boede) writes:

| It's a little bothersome to turn on "max. optimization" and have your code stop
| working! ;-)

  My manual calls this "unsafe optimization" or some such. Besides, you
get the wrong answer, but much faster!  ;-)
-- 
bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
    sysop *IX BBS and Public Access UNIX
    moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me

karl@robot.in-berlin.de (Karl-P. Huestegge) (12/14/90)

jon@ccwf.cc.utexas.edu (Jon Boede) writes:

>Hopefully I'm posting old news... but I found a rather insidious bug in cc
>version 1.6.  

It seems you're a little bit outdated with your release. ;-)

Xenix 386 2.3.2 comes with: 
      Microsoft 386 Compiler ver. 4.85
                ( was updated with lng095 to ver 5.1)
      Microsoft 286 Compiler Ver. 5.1 
      Unix 5.3 C Preprocessor
      Unix 5.3 curses

>Try: cc x.c; a.out; cc -Ox x.c; a.out; cc -Oal x.c; a.out

Always 'works ok' with MSC 386 5.1 on my system.

BTW: -Ox is default. And is the same as -Oactl. All three cc-commands
     produce the same code.

-- 
Karl-Peter Huestegge                       karl@robot.in-berlin.de
Berlin Friedenau                           ..unido!fub!geminix!robot!karl

dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) (12/14/90)

In article <1990Dec13.175120.12187@robot.in-berlin.de> karl@robot.in-berlin.de (Karl-P. Huestegge) writes:
>Always 'works ok' with MSC 386 5.1 on my system.
>
>BTW: -Ox is default. And is the same as -Oactl. All three cc-commands
>     produce the same code.

Nope. The default for -O is -Ot (optimize for time), not a, c, or l. 
-Ox (which is the same as -Oactl) relaxes alias checking so it can
change the semantics of your code if there is any aliasing going on.
Use it with great caution. 

I would have preferred to see their "maximum" optimization mean
maximum optimization that doesn't break correct code. 




--
Dave Eisen                      	    dkeisen@Gang-of-Four.Stanford.EDU
1447 N. Shoreline Blvd.
Mountain View, CA 94043           
(415) 967-5644