This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

how do I promise const to the optimizer?


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]