This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: attribute pure and gcse
- From: Dara Hazeghi <dhazeghi at yahoo dot com>
- To: Eljay Love-Jensen <eljay at adobe dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sat, 3 Apr 2004 09:20:40 -0800 (PST)
- Subject: Re: attribute pure and gcse
--- Eljay Love-Jensen <eljay@adobe.com> wrote:
Hello,
>
> What is "int square(int)" supposed to do?
Nothing actually :-) I just wanted an example of a
"pure" function which should in theory be CSEable
(from my understanding).
>
> If a is anything other than zero, a will be set to
> zero by the "a = 0 * a;"
> (when j := 0). And will remain zero for quite some
> time thereafter.
That's definitely true. My bad...
>
> Second, you may want to make square inline, so that
> it can be CSE'd.
Doesn't seem to help (added attribute
always_inline)...
But my understanding is that a pure function should
have no "side-effects" thus two calls to it with the
same arguments should be able to be eliminated in
favor of a single call. This is what I need, and what
I thought the manual was implying. Perhaps I'm reading
it wrong though...?
Dara
P.S. Here's the (fixed) source in question:
static int square(int a) __attribute__ ((pure));
static int square(int a)
{
int j=1, k=1;
while(j!=a)
{
k = j*k;
j++;
}
return k;
}
int main()
{
return square(100) * square(100);
}
__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/