Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ccut!kogwy!new1!roger From: roger@zuken.co.jp (Roger Meunier) Newsgroups: comp.sys.hp Subject: Re: C Compiler Optimizer Message-ID: Date: 29 Aug 90 14:16:47 GMT References: <59169@bbn.BBN.COM> Sender: news@new1.zuken.co.jp Organization: ZUKEN Inc. Yokohama, JAPAN Lines: 85 In-reply-to: ahill@bbn.com's message of 27 Aug 90 19:55:03 GMT In article <59169@bbn.BBN.COM> ahill@bbn.com (Alan R. Hill) writes: > We have experienced problems of varying symptoms while using >the optimizer switch of the HP-UX 7.0 C compiler. Rather than >extensively analyzing these problems we have opted to compile without >optimizing. Has anyone else noticed bad behavior with the optimizer? Indeed we have. The code given below optimizes cleanly under +O1, but the -O optimizer does manage registers properly. It doesn't handle cases where side affects may be introduced by function calls. --------------------------- Cut Here ------------------------------ #include void reg_and_stack(); void doit(); void doitagain(); main() { int parms[10]; parms[0] = -1; reg_and_stack(parms); } void reg_and_stack(parms) int* parms; { int id; int args[30]; short cnt; cnt = 0; if (parms) { doit(parms,&args[0],&cnt); if (parms[0] & 0x0020) id = parms[1]; } args[cnt] = 1; cnt++; args[cnt] = 2; cnt++; args[cnt] = 3; cnt++; doitagain(&args[0],&cnt); } void doit(parms,args,cnt) int* parms; int args[]; short* cnt; { printf("doit: on entry, cnt = %d\n",*cnt); *cnt = 2; printf("doit: on exit, cnt = %d\n",*cnt); } void doitagain(args,cnt) int args[]; short* cnt; { printf("doitagain: on entry, cnt = %d\n",*cnt); } --------------------------- Cut Here ------------------------------ % cc -o reg_stack +O1 reg_stack.c % reg_stack doit: on entry, cnt = 0 doit: on exit, cnt = 2 doitagain: on entry, cnt = 5 ^ % cc -o reg_stack -O reg_stack.c % reg_stack doit: on entry, cnt = 0 doit: on exit, cnt = 2 doitagain: on entry, cnt = 3 ^ A quick look at the assembly listing produced by the -O optimizer shows that while the stack version of cnt was set to 2 by doit(), the stack version is overwritten by the register version, which still contained the pre-doit() value of 0. -- Roger Meunier @ Zuken, Inc. Yokohama, Japan (roger@zuken.co.jp)