Bug 32401

Summary: [PPC/Altivec] Non optimal code structure with -mabi=altivec
Product: gcc Reporter: Przemysław Iskra <sparky>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: enhancement CC: bill.schmidt, dje, gcc-bugs, pinskia, segher, sparky
Priority: P3 Keywords: missed-optimization
Version: 4.3.0   
Target Milestone: ---   
Host: powerpc*-linux Target: powerpc*-linux
Build: powerpc*-linux Known to work:
Known to fail: 4.3.0 Last reconfirmed: 2016-01-29 00:00:00
Bug Depends on: 32429    
Bug Blocks:    

Description Przemysław Iskra 2007-06-19 13:06:31 UTC
With altivec enabled gcc prepares additional space on the stack. Unlike earlier versions gcc 4.3 removes stack modification instructions if it isn't used. With just -maltivec or with -mabi=altivec when altivec isn't used it works very well. But with -mabi=altivec and altivec used gcc produces code with stucture similar to one produced by eariler gcc versions with just stack modification instructions removed. Seems like stack isn't optimized early enough.


This simple code:

void
test ( int len )
{
	if (len) {
		vector unsigned char vSetTo = {};
		asm volatile ("" : : "v" (vSetTo) ); /* do something */
	}
}


"gcc-4.3 -O2 -maltivec -mregnames test.c -S" produces:

test:
	cmpwi %cr7,%r3,0
	beqlr- %cr7
	vxor %v0,%v0,%v0
	blr


while "gcc-4.3 -O2 -maltivec -mabi=altivec -mregnames test.c -S" produces:

test:
	cmpwi %cr7,%r3,0
	beq- %cr7,.L3      # <-- should be beqlr
	vxor %v0,%v0,%v0
.L3:
	blr


The letter one has same structure as produced by earlier gcc versions, but without stack modification instructions:

gcc 4.1.3 produces:

test:
	cmpwi %cr7,%r3,0
	stwu %r1,-16(%r1)
	vxor %v0,%v0,%v0
	beq- %cr7,.L4
.L4:
	addi %r1,%r1,16
	blr
Comment 1 David Edelsohn 2016-01-29 15:08:37 UTC
New
Comment 2 Segher Boessenkool 2017-03-01 09:34:24 UTC
This was fixed in GCC 5 or GCC 6.  So, closing this PR.