public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/62642] New: x86 rdtsc is moved through barrier
@ 2014-09-01 18:16 M8R-ynb11d at mailinator dot com
  2014-09-01 18:24 ` [Bug target/62642] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: M8R-ynb11d at mailinator dot com @ 2014-09-01 18:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 62642
           Summary: x86 rdtsc is moved through barrier
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: M8R-ynb11d at mailinator dot com

given:

unsigned long long measure(void (*func)(void))
{
    unsigned long long before = __builtin_ia32_rdtsc();
    asm volatile("" ::: "memory");
    func();
    asm volatile("" ::: "memory");
    unsigned long long after = __builtin_ia32_rdtsc();
    return after - before;
}

On x86 linux with -O2, this results in the obviously useless:

measure:
    push    edi
    push    esi
    push    ebx
    call    [DWORD PTR [esp+16]]
    rdtsc
    mov    esi, eax
    mov    edi, edx
    rdtsc
    pop    ebx
    sub    esi, eax
    sbb    edi, edx
    mov    eax, esi
    mov    edx, edi
    pop    esi
    pop    edi
    ret

I can reproduce the problem on 32 bit x86 on Linux and MinGW with 4.8.2 and
4.9.1. (I guess 4.8.0 also exhibits the problem but I don't have that available
for testing, so I set the version to 4.8.2 in the report.)

4.7.x and 4.6.x work correctly, as does 64 bit on both platforms.

If this is not the proper sanctioned way to write this function, I'm all ears
to a better way.  I've tried also adding calls to __builtin_ia32_mfence() which
as I understand it should not be necessary, and it gets even more comical:

        ...
    mfence
    call    [DWORD PTR [esp+16]]
    mfence
    rdtsc
    mov    esi, eax
    mov    edi, edx
    rdtsc
        ...


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

* [Bug target/62642] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
@ 2014-09-01 18:24 ` pinskia at gcc dot gnu.org
  2014-11-19 13:28 ` [Bug target/62642] [4.8/4.9 Regression] " rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-09-01 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-09-01
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem shows up in IRA stage.
New iteration of spill/restore move
+++Costs: overall -65521000, reg -65536000, mem 15000, ld 0, st 0, move 0
+++       move loops 0, new jumps 0
scanning new insn with uid = 22.
moving def of 88 (insn 6 now) deleting insn with uid = 21.
deleting insn with uid = 6.
rescanning insn with uid = 22.
 22) rather than keep unallocated replacement 93


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

* [Bug target/62642] [4.8/4.9 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
  2014-09-01 18:24 ` [Bug target/62642] " pinskia at gcc dot gnu.org
@ 2014-11-19 13:28 ` rguenth at gcc dot gnu.org
  2014-12-10 13:10 ` [Bug target/62642] [4.8/4.9/5 " rguenth at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-19 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.8.4


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

* [Bug target/62642] [4.8/4.9/5 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
  2014-09-01 18:24 ` [Bug target/62642] " pinskia at gcc dot gnu.org
  2014-11-19 13:28 ` [Bug target/62642] [4.8/4.9 Regression] " rguenth at gcc dot gnu.org
@ 2014-12-10 13:10 ` rguenth at gcc dot gnu.org
  2014-12-13  4:09 ` vmakarov at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-12-10 13:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ra
             Target|                            |i?86-*-*
           Priority|P3                          |P2
                 CC|                            |vmakarov at gcc dot gnu.org
            Summary|[4.8/4.9 Regression] x86    |[4.8/4.9/5 Regression] x86
                   |rdtsc is moved through      |rdtsc is moved through
                   |barrier                     |barrier

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed on trunk.


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

* [Bug target/62642] [4.8/4.9/5 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (2 preceding siblings ...)
  2014-12-10 13:10 ` [Bug target/62642] [4.8/4.9/5 " rguenth at gcc dot gnu.org
@ 2014-12-13  4:09 ` vmakarov at gcc dot gnu.org
  2014-12-15 20:04 ` vmakarov at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: vmakarov at gcc dot gnu.org @ 2014-12-13  4:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Vladimir Makarov <vmakarov at gcc dot gnu.org> ---
The problem is in a live range splitting optimization to reduce register
pressure.  It was introduced by

https://gcc.gnu.org/ml/gcc-patches/2011-12/msg01531.html

It is easy to switch off for this kind of insns.  I'll submit the patch on
Monday.


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

* [Bug target/62642] [4.8/4.9/5 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (3 preceding siblings ...)
  2014-12-13  4:09 ` vmakarov at gcc dot gnu.org
@ 2014-12-15 20:04 ` vmakarov at gcc dot gnu.org
  2014-12-17 10:35 ` M8R-ynb11d at mailinator dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: vmakarov at gcc dot gnu.org @ 2014-12-15 20:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Vladimir Makarov <vmakarov at gcc dot gnu.org> ---
Author: vmakarov
Date: Mon Dec 15 20:04:04 2014
New Revision: 218761

URL: https://gcc.gnu.org/viewcvs?rev=218761&root=gcc&view=rev
Log:
2014-12-15  Vladimir Makarov  <vmakarov@redhat.com>

    PR target/62642
    * ira.c (rtx_moveable_p): Prevent UNSPEC_VOLATILE moves.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ira.c


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

* [Bug target/62642] [4.8/4.9/5 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (4 preceding siblings ...)
  2014-12-15 20:04 ` vmakarov at gcc dot gnu.org
@ 2014-12-17 10:35 ` M8R-ynb11d at mailinator dot com
  2014-12-19 13:44 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: M8R-ynb11d at mailinator dot com @ 2014-12-17 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from M8R-ynb11d at mailinator dot com ---
I originally put the barriers there in a futile attempt to work around the bug.
 Can anyone tell me whether I actually need them, or whether the intrinsic
carries with it an implicit built-in barrier to prevent reordering?  Ideally
I'd like to write portable code using only intrinsics and not gcc-specific
asm() stuff, so I hope that it's the latter.


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

* [Bug target/62642] [4.8/4.9/5 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (5 preceding siblings ...)
  2014-12-17 10:35 ` M8R-ynb11d at mailinator dot com
@ 2014-12-19 13:44 ` jakub at gcc dot gnu.org
  2015-01-12 10:10 ` [Bug target/62642] [4.8/4.9 " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-12-19 13:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.8.4                       |4.8.5

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.8.4 has been released.


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

* [Bug target/62642] [4.8/4.9 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (6 preceding siblings ...)
  2014-12-19 13:44 ` jakub at gcc dot gnu.org
@ 2015-01-12 10:10 ` rguenth at gcc dot gnu.org
  2015-06-12  8:01 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-01-12 10:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |5.0
            Summary|[4.8/4.9/5 Regression] x86  |[4.8/4.9 Regression] x86
                   |rdtsc is moved through      |rdtsc is moved through
                   |barrier                     |barrier

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk.


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

* [Bug target/62642] [4.8/4.9 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (7 preceding siblings ...)
  2015-01-12 10:10 ` [Bug target/62642] [4.8/4.9 " rguenth at gcc dot gnu.org
@ 2015-06-12  8:01 ` jakub at gcc dot gnu.org
  2015-06-12 11:55 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-12  8:01 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Vlad, do you think this is backportable to 4.9 and 4.8?


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

* [Bug target/62642] [4.8/4.9 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (9 preceding siblings ...)
  2015-06-12 11:55 ` jakub at gcc dot gnu.org
@ 2015-06-12 11:55 ` jakub at gcc dot gnu.org
  2015-06-12 11:58 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-12 11:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri Jun 12 11:55:11 2015
New Revision: 224421

URL: https://gcc.gnu.org/viewcvs?rev=224421&root=gcc&view=rev
Log:
        Backported from mainline
        2014-12-15  Vladimir Makarov  <vmakarov@redhat.com>

        PR target/62642
        * ira.c (rtx_moveable_p): Prevent UNSPEC_VOLATILE moves.

Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/ira.c


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

* [Bug target/62642] [4.8/4.9 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (8 preceding siblings ...)
  2015-06-12  8:01 ` jakub at gcc dot gnu.org
@ 2015-06-12 11:55 ` jakub at gcc dot gnu.org
  2015-06-12 11:55 ` jakub at gcc dot gnu.org
  2015-06-12 11:58 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-12 11:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri Jun 12 11:54:43 2015
New Revision: 224420

URL: https://gcc.gnu.org/viewcvs?rev=224420&root=gcc&view=rev
Log:
        Backported from mainline
        2014-12-15  Vladimir Makarov  <vmakarov@redhat.com>

        PR target/62642
        * ira.c (rtx_moveable_p): Prevent UNSPEC_VOLATILE moves.

Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/ira.c


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

* [Bug target/62642] [4.8/4.9 Regression] x86 rdtsc is moved through barrier
  2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
                   ` (10 preceding siblings ...)
  2015-06-12 11:55 ` jakub at gcc dot gnu.org
@ 2015-06-12 11:58 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-12 11:58 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.


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

end of thread, other threads:[~2015-06-12 11:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-01 18:16 [Bug target/62642] New: x86 rdtsc is moved through barrier M8R-ynb11d at mailinator dot com
2014-09-01 18:24 ` [Bug target/62642] " pinskia at gcc dot gnu.org
2014-11-19 13:28 ` [Bug target/62642] [4.8/4.9 Regression] " rguenth at gcc dot gnu.org
2014-12-10 13:10 ` [Bug target/62642] [4.8/4.9/5 " rguenth at gcc dot gnu.org
2014-12-13  4:09 ` vmakarov at gcc dot gnu.org
2014-12-15 20:04 ` vmakarov at gcc dot gnu.org
2014-12-17 10:35 ` M8R-ynb11d at mailinator dot com
2014-12-19 13:44 ` jakub at gcc dot gnu.org
2015-01-12 10:10 ` [Bug target/62642] [4.8/4.9 " rguenth at gcc dot gnu.org
2015-06-12  8:01 ` jakub at gcc dot gnu.org
2015-06-12 11:55 ` jakub at gcc dot gnu.org
2015-06-12 11:55 ` jakub at gcc dot gnu.org
2015-06-12 11:58 ` jakub 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).