public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/45410]  New: constant not optimized / propagated
@ 2010-08-26  5:13 reza at parvan dot net
  2010-08-26  5:19 ` [Bug middle-end/45410] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: reza at parvan dot net @ 2010-08-26  5:13 UTC (permalink / raw)
  To: gcc-bugs

gcc -Wall -O3 -S test.c
doesn't seem to propagate constants correctly.

Notice that ss is declared static, therefor everything is known at compile
time.

Code:
#include <stdio.h>

struct s {int i;int j;};
struct s static ss={77,2};

int
main() 
{
        ss.j += 88;
        printf("%d\n",sizeof(ss));
        return ss.i+ss.j;
};


-- 
           Summary: constant not optimized / propagated
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reza at parvan dot net
  GCC host triplet: x86 Ubuntu Linux


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


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

* [Bug c/45410] constant not optimized / propagated
  2010-08-26  5:13 [Bug c/45410] New: constant not optimized / propagated reza at parvan dot net
  2010-08-26  5:19 ` [Bug middle-end/45410] " pinskia at gcc dot gnu dot org
@ 2010-08-26  5:19 ` pinskia at gcc dot gnu dot org
  2010-08-26  7:34 ` [Bug middle-end/45410] " jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-08-26  5:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-08-26 05:19 -------
Well GCC does not know much about main really.  It does not currently take into
account that ss cannot change before main.


-- 


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


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

* [Bug middle-end/45410] constant not optimized / propagated
  2010-08-26  5:13 [Bug c/45410] New: constant not optimized / propagated reza at parvan dot net
@ 2010-08-26  5:19 ` pinskia at gcc dot gnu dot org
  2010-08-26  5:19 ` [Bug c/45410] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-08-26  5:19 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
          Component|c                           |middle-end
           Keywords|                            |missed-optimization


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


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

* [Bug middle-end/45410] constant not optimized / propagated
  2010-08-26  5:13 [Bug c/45410] New: constant not optimized / propagated reza at parvan dot net
  2010-08-26  5:19 ` [Bug middle-end/45410] " pinskia at gcc dot gnu dot org
  2010-08-26  5:19 ` [Bug c/45410] " pinskia at gcc dot gnu dot org
@ 2010-08-26  7:34 ` jakub at gcc dot gnu dot org
  2010-08-26  9:46 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-08-26  7:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2010-08-26 07:33 -------
That's not the main problem here.  The problem is that this is an aggregate and
we SRA only automatic vars, not global vars.  And it isn't constant either
(neither declared, nor actually, so can't be detected as constant).  Special
handling of main would just add info that it is called only once in the
lifetime of the program.


-- 


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


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

* [Bug middle-end/45410] constant not optimized / propagated
  2010-08-26  5:13 [Bug c/45410] New: constant not optimized / propagated reza at parvan dot net
                   ` (2 preceding siblings ...)
  2010-08-26  7:34 ` [Bug middle-end/45410] " jakub at gcc dot gnu dot org
@ 2010-08-26  9:46 ` rguenth at gcc dot gnu dot org
  2010-08-26  9:59 ` jakub at gcc dot gnu dot org
  2010-08-27 17:59 ` reza at parvan dot net
  5 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-08-26  9:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2010-08-26 09:46 -------
Well, you need flow-sensitive analysis to figure out that when visiting
ss.j += 88; you can assume that ss.j is still 2.


-- 


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


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

* [Bug middle-end/45410] constant not optimized / propagated
  2010-08-26  5:13 [Bug c/45410] New: constant not optimized / propagated reza at parvan dot net
                   ` (3 preceding siblings ...)
  2010-08-26  9:46 ` rguenth at gcc dot gnu dot org
@ 2010-08-26  9:59 ` jakub at gcc dot gnu dot org
  2010-08-27 17:59 ` reza at parvan dot net
  5 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-08-26  9:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jakub at gcc dot gnu dot org  2010-08-26 09:59 -------
Sure, one that would also be able to assume that main is called just once.
Anyway, even to optimize ss.i into 77 you'd need a way to mark fields in global
aggregates as const if they aren't ever modified...


-- 


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


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

* [Bug middle-end/45410] constant not optimized / propagated
  2010-08-26  5:13 [Bug c/45410] New: constant not optimized / propagated reza at parvan dot net
                   ` (4 preceding siblings ...)
  2010-08-26  9:59 ` jakub at gcc dot gnu dot org
@ 2010-08-27 17:59 ` reza at parvan dot net
  5 siblings, 0 replies; 8+ messages in thread
From: reza at parvan dot net @ 2010-08-27 17:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from reza at parvan dot net  2010-08-27 17:59 -------
(In reply to comment #2)
> That's not the main problem here.  The problem is that this is an aggregate and
> we SRA only automatic vars, not global vars.  And it isn't constant either

Jakub,
Thanks for that insight.  Of course, gcc does a pretty good job (and flow
analysis) if we move 'struct s ss' into function scope.  That seems like a
reasonable workaround for many situations.

Reza.


-- 


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


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

* [Bug middle-end/45410] constant not optimized / propagated
       [not found] <bug-45410-4@http.gcc.gnu.org/bugzilla/>
@ 2012-02-02 17:28 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-02 17:28 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-02-02
     Ever Confirmed|0                           |1

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-02 17:28:36 UTC ---
Confirmed.


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

end of thread, other threads:[~2012-02-02 17:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-26  5:13 [Bug c/45410] New: constant not optimized / propagated reza at parvan dot net
2010-08-26  5:19 ` [Bug middle-end/45410] " pinskia at gcc dot gnu dot org
2010-08-26  5:19 ` [Bug c/45410] " pinskia at gcc dot gnu dot org
2010-08-26  7:34 ` [Bug middle-end/45410] " jakub at gcc dot gnu dot org
2010-08-26  9:46 ` rguenth at gcc dot gnu dot org
2010-08-26  9:59 ` jakub at gcc dot gnu dot org
2010-08-27 17:59 ` reza at parvan dot net
     [not found] <bug-45410-4@http.gcc.gnu.org/bugzilla/>
2012-02-02 17:28 ` pinskia at gcc dot gnu.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).