how do I promise const to the optimizer?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have an optimization issue, which can be demonstrated with this example: 

typedef struct
{
	char tag; 
	char data[255]; // too expensive to copy!
} val; 

extern int fun(const val * __restrict__ p,int i); 

int bar(const val *__restrict__ x, const int t) 
{
	return fun(x,x->tag*t)+fun(x,x->tag*t); 
}

The problem is, assembly reveals that the multiplication is done twice and gcc  
is obviously right by doing this, because it can't know whether calling fun() 
changes the contents of x by aliasing or casting.

However, I know, by chance, that after calling fun() (which may have all kinds 
of side-effects) x will always be unchanged, and as such x->tag*t can be 
subject to CSE. How do I apply such a strong guarantee? 

I can't do the CSE by hand, because in the actual code the situation arises 
from inlining overloaded operators in c++.

Marco

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux