/* I'm working on improving the speed of a public domain translator I wrote (for simulating circuits). From profiling, the generated code is loosing a lot due to load/store pressure. Looking at the assember, it ueems that the compiler is presuming pointer aliasing, and has about 2 times more mov's then necessary. So, can someone please tell me how to get rid of aliasing in the below snippit? I'm using: .ident "GCC: (GNU) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)" There's member routine(s) that operate on this*, and on a number of global structures referenced though a set of remote pointers. None of the pointers ever point to the same thing. When solved, I'd expect the code to look like the second function better() below. Again, this is machine generated code, so the solution doesn't have to be pretty, but can't involve copying the data (as the Rmt structure actually has thousands of elements). Thanks! */ struct Rmt { long remoteb; }; Rmt* __restrict__ rmtp; struct Lru { void better(); void bad(); long locala; }; //-------------------- static inline void BIT(int bit, long& lhs,long rhs) { lhs = lhs | rhs<<(bit); } void Lru::bad() __restrict__ { // This is the version with all the extra mov's // The assignment below doesn't help... Rmt* __restrict__ rmtx = rmtp; // movl 8(%ebp), %ebx BIT(1, locala, (rmtx->remoteb)); // movl rmtp, %ecx // movl (%ecx), %eax // sall $1, %eax // orl (%ebx), %eax // movl %eax, (%ebx) BIT(2, locala, (rmtx->remoteb)); // movl (%ecx), %edx // sall $2, %edx // orl %eax, %edx // movl %edx, (%ebx) BIT(3, locala, (rmtx->remoteb)); // movl (%ecx), %eax // sall $3, %eax // orl %edx, %eax // movl %eax, (%ebx) } void Lru::better() { // Here's an example which removes the extra mov's // It's not a practical solution my program however long localb = rmtp->remoteb; // movl 8(%ebp), %ebx // movl rmtp, %eax // movl (%eax), %eax BIT(1, locala, localb); // leal (%eax,%eax), %edx // orl (%ebx), %edx BIT(2, locala, localb); // leal 0(,%eax,4), %ecx // orl %edx, %ecx BIT(3, locala, localb); // sall $3, %eax // orl %ecx, %eax // movl %eax, (%ebx) } //################################################################### // Local Variables: // compile-command: "g++ -O1 -S restrict.cpp && cat restrict.s " // End: