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

[PATH] have gcse consider a compare with the same register as a constant (except for floating point)


This patch fixes a problem on PPC where it moves a compare out of a loop but the compare is actually constant at compile time but gcc would not remove the branch inside the loop, the code is derived from art in SPEC2000 :
void temp(int winner, int limit, int *x)
{
int i, test;
int p;
test = winner;
for(i = 0; i<limit;i++)
{
if (test == winner)
{
p = i<<2;
}
else
{
p = i*30;
}
x[i] = p;
}
}
Old gcc would produce:
_temp:
li r9,0
cmpw cr0,r9,r4
bgelr- cr0
cmpw cr7,r3,r3 <--- notice this is a compare before the loop and is constant.
mtctr r4
L20:
slwi r0,r9,2
mr r2,r0
beq- cr7,L16 <--- this branch will be always be taken
mulli r0,r9,30
slwi r2,r9,2
L16:
stwx r0,r2,r5
addi r9,r9,1
bdnz L20
blr



gcc with this patch, no extra branch in the loop: _temp: li r2,0 cmpw cr0,r2,r4 bgelr- cr0 mtctr r4 L20: slwi r3,r2,2 addi r2,r2,1 stwx r3,r3,r5 bdnz L20 blr

Another case I have to include -fno-guess-branch-probability because gcc gets the basic blocks wrong for some reason, I think it is because of gcse pulling rtl out of a loop and not putting it into its own bb but the bb for inside of the loop.


ChangeLog:


2003-05-02 Andrew Pinski <pinskia@physics.uc.edu>

	* gcse.c (gcse_constant_p): COMPARE of the same registers is a constant
	if they are not floating point registers.

Patch:

Attachment: gcse.diff
Description: Binary data



Bootstraped and tested on i686-unknown-openbsd3.1.
Bootstraped on powerpc-apple-darwin6.5 also,
	but not testing because I do not have a fixed kernel.


Thanks, Andrew Pinski

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