public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/50677] New: volatile forces load into register
@ 2011-10-09 12:52 marc.glisse at normalesup dot org
  2011-10-09 17:36 ` [Bug rtl-optimization/50677] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: marc.glisse at normalesup dot org @ 2011-10-09 12:52 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50677
           Summary: volatile forces load into register
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: marc.glisse@normalesup.org
              Host: x86_64-linux-gnu


Compiling this simple program (-Ofast):

void f(int volatile*i){++*i;}

produces this code:

    movl    (%rdi), %eax
    addl    $1, %eax
    movl    %eax, (%rdi)

(or incl %eax for the central line with -Os).

However, if I remove "volatile", I get the nicer:

    addl    $1, (%rdi)

(or incl (%rdi) with -Os).

The second version seems legal to me even in the volatile case, is that wrong?

There might be a relation to this thread:
http://gcc.gnu.org/ml/gcc/2011-10/msg00006.html
(no volatile there, but a failure to fuse load+add+store)

This is particularly noticable because people (wrongly) use volatile for
threaded code and the 3 instruction version is likely even more racy than the
one with a single instruction.

(sorry if the category is wrong, I just picked one with "optimization" in the
name...)


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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
@ 2011-10-09 17:36 ` rguenth at gcc dot gnu.org
  2011-10-09 19:49 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-10-09 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-10-09
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-09 17:36:30 UTC ---
Well, the issue is that most optimization passes just don't do anything
for volatile qualified accesses.  That's a safe thing.  Deciding what
kind of optimizations are allowed for volatile accesses might introduce bugs,
and sofar the consensus was "volatile?  don't bother with optimization, it'll
be slow anyway".

It very likely is combine that gives up here.


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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
  2011-10-09 17:36 ` [Bug rtl-optimization/50677] " rguenth at gcc dot gnu.org
@ 2011-10-09 19:49 ` pinskia at gcc dot gnu.org
  2014-02-24 16:03 ` hjl.tools at gmail dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-10-09 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-10-09 19:48:39 UTC ---
This is a dup of an older bug too though I cannot find it right now.  Also it
is related to bug 49807.


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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
  2011-10-09 17:36 ` [Bug rtl-optimization/50677] " rguenth at gcc dot gnu.org
  2011-10-09 19:49 ` pinskia at gcc dot gnu.org
@ 2014-02-24 16:03 ` hjl.tools at gmail dot com
  2014-02-24 16:17 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2014-02-24 16:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> ---
Combine generates

Trying 6, 7 -> 8:
Failed to match this instruction:
(set (mem/v:SI (reg/v/f:DI 85 [ i ]) [2 *i_2(D)+0 S4 A32])
    (plus:SI (mem/v:SI (reg/v/f:DI 85 [ i ]) [2 *i_2(D)+0 S4 A32])
        (const_int 1 [0x1])))

from

(insn 6 3 7 2 (set (reg:SI 83 [ D.1752 ])
        (mem/v:SI (reg/v/f:DI 85 [ i ]) [2 *i_2(D)+0 S4 A32])) x.i:1 90
{*movsi_
internal}
     (nil))
(insn 7 6 8 2 (parallel [
            (set (reg:SI 84 [ D.1752 ])
                (plus:SI (reg:SI 83 [ D.1752 ])
                    (const_int 1 [0x1])))
            (clobber (reg:CC 17 flags))
        ]) x.i:1 266 {*addsi_1}
     (expr_list:REG_DEAD (reg:SI 83 [ D.1752 ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))

Why doesn't combine include (clobber (reg:CC 17 flags))?


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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
                   ` (2 preceding siblings ...)
  2014-02-24 16:03 ` hjl.tools at gmail dot com
@ 2014-02-24 16:17 ` pinskia at gcc dot gnu.org
  2015-07-15 16:37 ` hjl.tools at gmail dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-02-24 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #4)
> Why doesn't combine include (clobber (reg:CC 17 flags))?

It has nothing to do with the clobber.
Inside combine_instructions there is a call to init_recog_no_volatile which
forces volatile memory not be recognized.  The main reason is because combine
does not check for volatile memory issues before doing the combine so it was
easier to just disable recognizability of volatile memory.


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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
                   ` (3 preceding siblings ...)
  2014-02-24 16:17 ` pinskia at gcc dot gnu.org
@ 2015-07-15 16:37 ` hjl.tools at gmail dot com
  2015-07-15 17:07 ` hjl.tools at gmail dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2015-07-15 16:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50677

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tkoeppe at google dot com

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
*** Bug 66881 has been marked as a duplicate of this bug. ***


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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
                   ` (4 preceding siblings ...)
  2015-07-15 16:37 ` hjl.tools at gmail dot com
@ 2015-07-15 17:07 ` hjl.tools at gmail dot com
  2021-11-29  3:17 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2015-07-15 17:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50677

--- Comment #7 from H.J. Lu <hjl.tools at gmail dot com> ---
Can we make init_recog_no_volatile processor a target hook so
that it can be disabled for x86?


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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
                   ` (5 preceding siblings ...)
  2015-07-15 17:07 ` hjl.tools at gmail dot com
@ 2021-11-29  3:17 ` pinskia at gcc dot gnu.org
  2022-09-27 23:37 ` pinskia at gcc dot gnu.org
  2023-02-09 18:11 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-29  3:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50677

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization

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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
                   ` (6 preceding siblings ...)
  2021-11-29  3:17 ` pinskia at gcc dot gnu.org
@ 2022-09-27 23:37 ` pinskia at gcc dot gnu.org
  2023-02-09 18:11 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-27 23:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50677

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hiraditya at msn dot com

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 107063 has been marked as a duplicate of this bug. ***

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

* [Bug rtl-optimization/50677] volatile forces load into register
  2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
                   ` (7 preceding siblings ...)
  2022-09-27 23:37 ` pinskia at gcc dot gnu.org
@ 2023-02-09 18:11 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-09 18:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50677

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

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

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Really dup of bug 3506.

*** This bug has been marked as a duplicate of bug 3506 ***

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

end of thread, other threads:[~2023-02-09 18:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-09 12:52 [Bug rtl-optimization/50677] New: volatile forces load into register marc.glisse at normalesup dot org
2011-10-09 17:36 ` [Bug rtl-optimization/50677] " rguenth at gcc dot gnu.org
2011-10-09 19:49 ` pinskia at gcc dot gnu.org
2014-02-24 16:03 ` hjl.tools at gmail dot com
2014-02-24 16:17 ` pinskia at gcc dot gnu.org
2015-07-15 16:37 ` hjl.tools at gmail dot com
2015-07-15 17:07 ` hjl.tools at gmail dot com
2021-11-29  3:17 ` pinskia at gcc dot gnu.org
2022-09-27 23:37 ` pinskia at gcc dot gnu.org
2023-02-09 18:11 ` 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).