This is the mail archive of the
mailing list for the GCC project.
RE: Release novops attribute for external use?
> Surely printf writes to global memory (it clobbers the stdout FILE*)
OK, the point is not about whether printf is pure or not. Instead, if
programmer knows the callee function such as printf contains no
memory access that affects operations inside caller function, and he
would like to have a way to optimize the code. Our engineer gave following
void myfunc(MyStruct *myStruct)
a = myStruct->a;
b = 2*mystruct->a; // I would like to have the compiler acting as if I had written b = 2*a;
Providing such attribute may be potentially dangerous. But it is just
like "restrict" qualifier and some other attributes, putting responsibilty
of correctness on the programmer. "novops" seems to achieve that effect,
though its semantics doesn't match exactly what I described.
> As for the original question - novops is internal only because its
> semantics is purely internal and changes with internal aliasing
> Now, we still lack a compelling example to see what exact semantics
> you are requesting? I suppose it might be close to a pure but
> volatile function? Which you could simulate by
> dummy = pure_fn ();
> asm ("" : "g" (dummy));
> or even
> volatile int dummy = pure_fn ();
These two methods still generate extra code to reload variables
> > Bingfeng
> >> -----Original Message-----
> >> From: firstname.lastname@example.org [mailto:email@example.com] On
> >> Behalf Of Andrew Haley
> >> Sent: 12 April 2010 17:34
> >> To: firstname.lastname@example.org
> >> Subject: Re: Release novops attribute for external use?
> >> On 04/12/2010 05:27 PM, Bingfeng Mei wrote:
> >> > Hello,
> >> > One of our engineers requested a feature so that
> >> > compiler can avoid to re-load variables after a function
> >> > call if it is known not to write to memory. It should
> >> > slash considerable code size in our applications. I found
> >> > the existing "pure" and "const" cannot meet his requirements
> >> > because the function is optimized out if it doesn't return
> >> > a value.
> >> If a function doesn't write to memory and it doesn't return a
> >> value, what is the point of calling it?
> >> Andrew.