public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays
@ 2003-10-28 14:47 bangerth at dealii dot org
  2003-10-28 15:25 ` [Bug optimization/12814] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2003-10-28 14:47 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Missed optimization with non-static but non-changing
                    local arrays
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bangerth at dealii dot org
                CC: gcc-bugs at gcc dot gnu dot org

For this small code snippet:
-------------------
int f1 (const int i) 
{
  const int x[3] = { 13, 26, 39 };
  return x[i];
}

int f2 (const int i) 
{
  static const int x[3] = { 13, 26, 39 };
  return x[i];
}
-------------------
here is essentially what we get on x86 with -O3 and
-fomit-frame-pointer with all present branches:
-------------------
_Z2f1i:
	subl	$28, %esp
	movl	$26, %ecx
	movl	32(%esp), %eax
	movl	$13, (%esp)
	movl	$39, %edx
	movl	%ecx, 4(%esp)
	movl	%edx, 8(%esp)
	movl	(%esp,%eax,4), %eax
	addl	$28, %esp
	ret

_ZZ2f2iE1x:
	.long	13
	.long	26
	.long	39
_Z2f2i:
	movl	4(%esp), %eax
	movl	_ZZ2f2iE1x(,%eax,4), %eax
	ret
------------------
Obviously, the code for f2 is more efficient than that for f1.
Things get even worse if the array gets larger, since then its
contents are spilled onto the stack in f1. 

The point is that this is really not necessary: gcc certainly has all
the abilities to detect that the array in f1 is unchanging and that it
could be treated as static even though it is not declared as
that. Note also that the code generated for f2 _never_ uses more
memory than that in f1, since the code for writing a constant into a
register or a stack slot uses _more_ memory than having the constant
in a table.

W.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
@ 2003-10-28 15:25 ` pinskia at gcc dot gnu dot org
  2003-10-29  0:36 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-28 15:25 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
  2003-10-28 15:25 ` [Bug optimization/12814] " pinskia at gcc dot gnu dot org
@ 2003-10-29  0:36 ` pinskia at gcc dot gnu dot org
  2003-12-26  2:22 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-29  0:36 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |pessimizes-code
   Last reconfirmed|0000-00-00 00:00:00         |2003-10-29 00:35:10
               date|                            |


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-10-29 00:35 -------
I can confirm this on the mainline (20031028).


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
  2003-10-28 15:25 ` [Bug optimization/12814] " pinskia at gcc dot gnu dot org
  2003-10-29  0:36 ` pinskia at gcc dot gnu dot org
@ 2003-12-26  2:22 ` pinskia at gcc dot gnu dot org
  2004-01-22  0:58 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-26  2:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-26 02:04 -------
Even happens on the tree-ssa.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2003-10-29 00:35:10         |2003-12-26 02:04:08
               date|                            |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
                   ` (2 preceding siblings ...)
  2003-12-26  2:22 ` pinskia at gcc dot gnu dot org
@ 2004-01-22  0:58 ` pinskia at gcc dot gnu dot org
  2004-01-28  9:37 ` rth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-22  0:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-22 00:57 -------
RTH said he would take care of this.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rth at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Target Milestone|---                         |tree-ssa


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
                   ` (3 preceding siblings ...)
  2004-01-22  0:58 ` pinskia at gcc dot gnu dot org
@ 2004-01-28  9:37 ` rth at gcc dot gnu dot org
  2004-01-28 15:06 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rth at gcc dot gnu dot org @ 2004-01-28  9:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rth at gcc dot gnu dot org  2004-01-28 09:36 -------
This specific test case is solved by the patch for PR13798.

One can still argue that we can notice that the array, even though not marked
"const", is never modified and so could be promoted to static readonly.  This 
is unlikely to happen soon.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|rth at gcc dot gnu dot org  |unassigned at gcc dot gnu
                   |                            |dot org
             Status|ASSIGNED                    |NEW


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
                   ` (4 preceding siblings ...)
  2004-01-28  9:37 ` rth at gcc dot gnu dot org
@ 2004-01-28 15:06 ` bangerth at dealii dot org
  2004-01-28 16:06 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-01-28 15:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-01-28 15:06 -------
Fixed indeed. For the cases I had in mind (and that are in the testcase) the arrays 
were always marked "const" but not "static". This is now handled properly. The fact 
that gcc could mark unchanging variables as if they were "const" is another thing, but 
not subject of this PR. 
 
Thanks 
  W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
                   ` (6 preceding siblings ...)
  2004-01-28 16:06 ` pinskia at gcc dot gnu dot org
@ 2004-01-28 16:06 ` pinskia at gcc dot gnu dot org
  2004-03-25 13:49 ` bangerth at dealii dot org
  2004-05-13 20:52 ` [Bug rtl-optimization/12814] " pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-28 16:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-28 16:06 -------
And now suspending it as it is fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |SUSPENDED


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
                   ` (5 preceding siblings ...)
  2004-01-28 15:06 ` bangerth at dealii dot org
@ 2004-01-28 16:06 ` pinskia at gcc dot gnu dot org
  2004-01-28 16:06 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-28 16:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-28 16:06 -------
reopening as this is only fixed on the tree-ssa branch and really was not fixed on any other branch 
either.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
                   ` (7 preceding siblings ...)
  2004-01-28 16:06 ` pinskia at gcc dot gnu dot org
@ 2004-03-25 13:49 ` bangerth at dealii dot org
  2004-05-13 20:52 ` [Bug rtl-optimization/12814] " pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-03-25 13:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-03-25 13:49 -------
*** Bug 14726 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrnobo1024 at yahoo dot com


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug rtl-optimization/12814] Missed optimization with non-static but non-changing local arrays
  2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
                   ` (8 preceding siblings ...)
  2004-03-25 13:49 ` bangerth at dealii dot org
@ 2004-05-13 20:52 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-13 20:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-13 11:45 -------
Fixed for 3.5.0 by the merge of the tree-ssa.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|SUSPENDED                   |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|tree-ssa                    |3.5.0


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-05-13 11:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-28 14:47 [Bug optimization/12814] New: Missed optimization with non-static but non-changing local arrays bangerth at dealii dot org
2003-10-28 15:25 ` [Bug optimization/12814] " pinskia at gcc dot gnu dot org
2003-10-29  0:36 ` pinskia at gcc dot gnu dot org
2003-12-26  2:22 ` pinskia at gcc dot gnu dot org
2004-01-22  0:58 ` pinskia at gcc dot gnu dot org
2004-01-28  9:37 ` rth at gcc dot gnu dot org
2004-01-28 15:06 ` bangerth at dealii dot org
2004-01-28 16:06 ` pinskia at gcc dot gnu dot org
2004-01-28 16:06 ` pinskia at gcc dot gnu dot org
2004-03-25 13:49 ` bangerth at dealii dot org
2004-05-13 20:52 ` [Bug rtl-optimization/12814] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).