public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54500] New: While(TRUE) loop optimization of global struct variables
@ 2012-09-06  8:38 tma at email dot cz
  2012-09-06  9:51 ` [Bug c/54500] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: tma at email dot cz @ 2012-09-06  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54500
           Summary: While(TRUE) loop optimization of global struct
                    variables
    Classification: Unclassified
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tma@email.cz
            Target: avr-*
             Build: WinAVR 20081205


I have large global static structure with substructers, longs etc.

struct {

  longs ...
  structs ...
  struct {
    boolean isEnd;
  } ss;
  etc.


} gs;

void procedure() {

  while(true) {
    if (gs.ss.isEnd) {
      if (an_cond1) {
        break;
      }
    }
    if (an_cond2) {
      break;
    }
    do_access_and_modify_gs_fields;
    gs.ss.isEnd = TRUE;
    do_access_and_modify_gs_fields;
  }

  if (gs.ss.IsEnd) {
  }

when used in "neverending" while with breaks then gcc fails to optimize
correctly changed fields of global structure. Gcc tries to cache field used in
loop into registers and when no more registers on the stack (what is benefit 
of copying vars from global variable onto stack ???). Changed values are
flushed back into global variable when loop terminates. There are several
breaks how to exit the loop. Suprisingly every loop has "copy&pasted" the same
exit code (why don't reuse one to save some memory ??). Respectively they
should be at least equal but in my case one of them did not flush back one
field (gs.isEnd after loop get unupdated value). I tried somehow persuade gcc
to know that isEnd is really modified by asm inline code. Sucessfully but any
change of code may change optimization and it appears again in another form.

Currently is problem that "gs.isEnd = TRUE;" updates optimized value in
register but "if (gs.ss.isEnd)" in loop check again global memory.

Seems gcc is totally confused with this construction. I hope setting struct as
volatile should help. 

avr-g++ -MM -mmcu=atmega2560 -g -Os -Wall -Wextra -w -ffunct
ion-sections -fdata-sections -fno-exceptions my.cpp -MF my.d -MT my.o


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

* [Bug c/54500] While(TRUE) loop optimization of global struct variables
  2012-09-06  8:38 [Bug c/54500] New: While(TRUE) loop optimization of global struct variables tma at email dot cz
@ 2012-09-06  9:51 ` rguenth at gcc dot gnu.org
  2012-09-15  9:21 ` [Bug other/54500] " gjl at gcc dot gnu.org
  2013-03-03 16:56 ` gjl at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-09-06  9:51 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2012-09-06
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-09-06 09:51:13 UTC ---
This is not a testcase that can be compiled, please provide one so we can
reproduce the issue and analyze it.  Please also try a more recent compiler,
4.3.2 is out of maintainance since several years - try at least GCC 4.6.3.


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

* [Bug other/54500] While(TRUE) loop optimization of global struct variables
  2012-09-06  8:38 [Bug c/54500] New: While(TRUE) loop optimization of global struct variables tma at email dot cz
  2012-09-06  9:51 ` [Bug c/54500] " rguenth at gcc dot gnu.org
@ 2012-09-15  9:21 ` gjl at gcc dot gnu.org
  2013-03-03 16:56 ` gjl at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: gjl at gcc dot gnu.org @ 2012-09-15  9:21 UTC (permalink / raw)
  To: gcc-bugs

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

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|avr-*                       |avr
   Last reconfirmed|2012-09-06 00:00:00         |
          Component|c                           |other
              Build|WinAVR 20081205             |
           Severity|major                       |normal


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

* [Bug other/54500] While(TRUE) loop optimization of global struct variables
  2012-09-06  8:38 [Bug c/54500] New: While(TRUE) loop optimization of global struct variables tma at email dot cz
  2012-09-06  9:51 ` [Bug c/54500] " rguenth at gcc dot gnu.org
  2012-09-15  9:21 ` [Bug other/54500] " gjl at gcc dot gnu.org
@ 2013-03-03 16:56 ` gjl at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: gjl at gcc dot gnu.org @ 2013-03-03 16:56 UTC (permalink / raw)
  To: gcc-bugs


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

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
                 CC|                            |gjl at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #2 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2013-03-03 16:55:28 UTC ---
No answer and no valid test case for 6 months now.  Closed as invalid.


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

end of thread, other threads:[~2013-03-03 16:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-06  8:38 [Bug c/54500] New: While(TRUE) loop optimization of global struct variables tma at email dot cz
2012-09-06  9:51 ` [Bug c/54500] " rguenth at gcc dot gnu.org
2012-09-15  9:21 ` [Bug other/54500] " gjl at gcc dot gnu.org
2013-03-03 16:56 ` gjl 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).