Newsgroups: comp.arch Path: utzoo!utgpu!cunews!bnrgate!bigsur!bcarh680!coopteam From: coopteam@bcarh680.bnr.ca (Jean Laliberte) Subject: Re: Optimising C compiler question Message-ID: <1991Apr15.134417.24380@bigsur.uucp> Sender: news@bigsur.uucp Organization: Bell Northern Research, Ottawa, Canada References: <1991Apr8.193155.3911@vax5.cit.cornell.edu> <1991Apr11.003431.24918@alzabo.ocunix.on.ca> <9526@cognos.UUCP> Distribution: comp Date: Mon, 15 Apr 91 13:44:17 GMT In article <9526@cognos.UUCP> jimp@cognos.UUCP (Jim Patterson) writes: >I don't think a compiler can ever know absolutely that a given variable >should be in a register whereas another should not, for "performance". >It can't do anything more than guess at the actual code dynamics, and >therefore would be allocating registers based on assumptions which >could be totally erronous. Here's an example which should illustrate >this. > >[description deleted] > >for (i=0 ; i<10000; ++i) { > e=malloc(sizeof(element)); > if (!e) { > for (j=0; j<10000; ++j) > if (j < i) > free(table[j]); > getout(); /* Leave routine now */ > } > table[i] = e; >} > Is there some reason register allocation couldn't also be dynamic? In this example, i would be stored in the register for the most part, but when the if() statement evaluates to true, 'store i' and 'load j' instructions would be executed, and j would then be the register variable (when the if() condition is over, i would be put back in the register). I think this would be faster than choosing one variable or the other. >-- >Jim Patterson Cognos Incorporated >UUCP:uunet!mitel!cunews!cognos!jimp P.O. BOX 9707 >PHONE:(613)738-1440 x6112 3755 Riverside Drive >NOT a Jays fan (not even a fan) Ottawa, Ont K1G 3Z4 no signature. std disclaimer. using a 6809 which *does* only allow one register variable.