Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 39621
Product:  
Component:  
Status: NEW
Resolution:
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Wouter van Gulik <wvangulik@xs4all.nl>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
main.c C file showing bug application/octet-stream 2009-04-03 08:48 359 bytes Edit
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 39621 depends on: Show dependency tree
Show dependency graph
Bug 39621 blocks:

Additional Comments:





Mark bug as waiting for feedback
Mark bug as suspended




View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2009-04-30 07:54 Opened: 2009-04-03 08:47
Function like this:

extern int bar(void);
int foo(int in)
{
 in += bar();
 in += bar(); 
 in += bar(); 
 in += bar(); 
 return in;
}

Result in putting the output of bar on stack, and adding the result just before
returning. It continues on until it about 16 iteration. Meaning useless heavy
stack usage and for some targets much code.

The general assembler will look like this:

push stack
call bar
put result on stack
call bar
put result on stack
call bar
put result on stack
call bar
add to in
add stack to in
add stack to in
add stack to in
pop stack
return 

This behaviour is seen on recent version for arm (4.3.3), x86 (4.3.3) and avr
(4.3.2).

Interresting is that providing the 'register' keyword on input for -00 'solves'
the problem.

It seems that GCC delays the add operations until returning, however delaying
beyond a function call is normally pointless and more expensive in terms of
code size and cycles.

See attached file for a test case with for unroll-loops and normal code.

------- Comment #1 From Wouter van Gulik 2009-04-03 08:48 -------
Created an attachment (id=17580) [edit]
C file showing bug

compile using:
gcc -S -funroll-loops -0[0123s] main.c

------- Comment #2 From Hans-Peter Nilsson 2009-04-06 17:16 -------
It'd be nice to know if -fno-tree-reassoc helped here.

------- Comment #3 From Wouter van Gulik 2009-04-07 07:55 -------
(In reply to comment #2)
> It'd be nice to know if -fno-tree-reassoc helped here.
> 

Yes that solves the problem. I tried for -O[123s] (x86 and avr).

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug