This is the mail archive of the gcc-bugs@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]

[Bug optimization/14685] New: Restrict of non-this pointer doesn't prevent unnecessary aliasing


/*

I'm working on improving the speed of a public domain translator I wrote
(for simulating circuits).  From profiling, the generated code is getting
killed due to load/store pressure.  Looking at the assember, it seems 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 in 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++ -O2 -S restrict.cpp && cat restrict.s "
// End:

-- 
           Summary: Restrict of non-this pointer doesn't prevent unnecessary
                    aliasing
           Product: gcc
           Version: 3.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wsnyder at wsnyder dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14685


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]