public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/55139] New: __atomic store does not support __ATOMIC_HLE_RELEASE
@ 2012-10-30 16:59 andi-gcc at firstfloor dot org
  2012-11-07  4:04 ` [Bug target/55139] " andi-gcc at firstfloor dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: andi-gcc at firstfloor dot org @ 2012-10-30 16:59 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55139
           Summary: __atomic store does not support __ATOMIC_HLE_RELEASE
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: andi-gcc@firstfloor.org


volatile int slock;

void unlock(void)
{
        int free_val = 1;
        __atomic_store(&slock, &free_val,
__ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE);
}

spin.c: In function 'unlock':
spin.c:6:16: warning: invalid memory model argument 3 of '__atomic_store'
[-Winvalid-memory-model]
  __atomic_store(&slock, &free_val, __ATOMIC_RELEASE|__ATOMIC_HLE_RELEASE);


But XRELEASE MOV ... is allowed in TSX.


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

* [Bug target/55139] __atomic store does not support __ATOMIC_HLE_RELEASE
  2012-10-30 16:59 [Bug target/55139] New: __atomic store does not support __ATOMIC_HLE_RELEASE andi-gcc at firstfloor dot org
@ 2012-11-07  4:04 ` andi-gcc at firstfloor dot org
  2012-11-07 14:31 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: andi-gcc at firstfloor dot org @ 2012-11-07  4:04 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Andi Kleen <andi-gcc at firstfloor dot org> 2012-11-07 04:03:53 UTC ---
This is an interesting one. This is the gcc code:

enum memmodel
{
  MEMMODEL_RELAXED = 0,
  MEMMODEL_CONSUME = 1,
  MEMMODEL_ACQUIRE = 2,
  MEMMODEL_RELEASE = 3,
  MEMMODEL_ACQ_REL = 4,
  MEMMODEL_SEQ_CST = 5,
  MEMMODEL_LAST = 6
};
#define MEMMODEL_MASK ((1<<16)-1)

 enum memmodel model;

  model = get_memmodel (CALL_EXPR_ARG (exp, 2));
  if ((model & MEMMODEL_MASK) != MEMMODEL_RELAXED
      && (model & MEMMODEL_MASK) != MEMMODEL_SEQ_CST
      && (model & MEMMODEL_MASK) != MEMMODEL_RELEASE)
    {
      error ("invalid memory model for %<__atomic_store%>");
      return NULL_RTX;
    }

HLE_STORE is 1 << 16, so outside the enum range

But when looking at the assembler we see that the & MEMMODEL_MASK
gets optimized away, it just generates a direct sequence of 32bit cmps.  

This makes all the != fail, even though they should succeed

I presume the optimizer assumes nothing can be outside the enum.

I tried to expand the enum by adding

  MEMMODEL_ARCH1 =  1 << 16,
  MEMMODEL_ARCH2 =  1 << 17,
  MEMMODEL_ARCH3 =  1 << 18,
  MEMMODEL_ARCH4 =  1 << 19

But still doesn't work.

Questions:
- Is it legal for the optimizer to assume this?
- Why does extending the enum not help?

We could fix it by not using an enum here of course, but I wonder if this is an
underlying optimizer bug.


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

* [Bug target/55139] __atomic store does not support __ATOMIC_HLE_RELEASE
  2012-10-30 16:59 [Bug target/55139] New: __atomic store does not support __ATOMIC_HLE_RELEASE andi-gcc at firstfloor dot org
  2012-11-07  4:04 ` [Bug target/55139] " andi-gcc at firstfloor dot org
@ 2012-11-07 14:31 ` jakub at gcc dot gnu.org
  2012-11-07 14:45 ` andi-gcc at firstfloor dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-11-07 14:31 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-07 14:30:49 UTC ---
What compiler compiled the code?  Older g++s would optimize it away, but newer
ones should have -fno-strict-enums by default.  That said, guess it would be
better to rewrite it to use int anyway.


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

* [Bug target/55139] __atomic store does not support __ATOMIC_HLE_RELEASE
  2012-10-30 16:59 [Bug target/55139] New: __atomic store does not support __ATOMIC_HLE_RELEASE andi-gcc at firstfloor dot org
  2012-11-07  4:04 ` [Bug target/55139] " andi-gcc at firstfloor dot org
  2012-11-07 14:31 ` jakub at gcc dot gnu.org
@ 2012-11-07 14:45 ` andi-gcc at firstfloor dot org
  2012-11-09 14:06 ` andi-gcc at firstfloor dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: andi-gcc at firstfloor dot org @ 2012-11-07 14:45 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Andi Kleen <andi-gcc at firstfloor dot org> 2012-11-07 14:45:17 UTC ---
I saw the problem both with bootstrapped and non bootstrapped (4.6 base)
compilers
I haven't checked if it's always the missing and, but it's likely

Ok I can change everything to int, but why did extending the enum not help?
I fear that I may hide some bug this way.

Also how to fix libstdc++? It seems to have a similar enum in its headers
(it doesn't support HLE yet, but that's another bug)


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

* [Bug target/55139] __atomic store does not support __ATOMIC_HLE_RELEASE
  2012-10-30 16:59 [Bug target/55139] New: __atomic store does not support __ATOMIC_HLE_RELEASE andi-gcc at firstfloor dot org
                   ` (2 preceding siblings ...)
  2012-11-07 14:45 ` andi-gcc at firstfloor dot org
@ 2012-11-09 14:06 ` andi-gcc at firstfloor dot org
  2012-11-09 15:24 ` ak at gcc dot gnu.org
  2024-04-09  3:22 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: andi-gcc at firstfloor dot org @ 2012-11-09 14:06 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from Andi Kleen <andi-gcc at firstfloor dot org> 2012-11-09 14:06:20 UTC ---
My earlier analysis was not correct. I was chasing the wrong warning.
Rather the problem is in c-common.c, where the atomic models are checked again.
I'm sending a patch for that.


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

* [Bug target/55139] __atomic store does not support __ATOMIC_HLE_RELEASE
  2012-10-30 16:59 [Bug target/55139] New: __atomic store does not support __ATOMIC_HLE_RELEASE andi-gcc at firstfloor dot org
                   ` (3 preceding siblings ...)
  2012-11-09 14:06 ` andi-gcc at firstfloor dot org
@ 2012-11-09 15:24 ` ak at gcc dot gnu.org
  2024-04-09  3:22 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ak at gcc dot gnu.org @ 2012-11-09 15:24 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from ak at gcc dot gnu.org 2012-11-09 15:24:32 UTC ---
Author: ak
Date: Fri Nov  9 15:24:25 2012
New Revision: 193363

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193363
Log:
Handle target specific memory models in C frontend

get_atomic_generic_size would error out for
__atomic_store(...,__ATOMIC_HLE_RELEASE)

Just mask it out. All the memory orders are checked completely
in builtins.c anyways.

I'm not sure what that check is for, it could be removed in theory.

Passed bootstrap and test suite on x86-64

gcc/c-family/:
2012-11-09  Andi Kleen  <ak@linux.intel.com>

    PR 55139
    * c-common.c (get_atomic_generic_size): Mask with
        MEMMODEL_MASK

Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c


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

* [Bug target/55139] __atomic store does not support __ATOMIC_HLE_RELEASE
  2012-10-30 16:59 [Bug target/55139] New: __atomic store does not support __ATOMIC_HLE_RELEASE andi-gcc at firstfloor dot org
                   ` (4 preceding siblings ...)
  2012-11-09 15:24 ` ak at gcc dot gnu.org
@ 2024-04-09  3:22 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-09  3:22 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |4.8.0

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed a long time ago.

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

end of thread, other threads:[~2024-04-09  3:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-30 16:59 [Bug target/55139] New: __atomic store does not support __ATOMIC_HLE_RELEASE andi-gcc at firstfloor dot org
2012-11-07  4:04 ` [Bug target/55139] " andi-gcc at firstfloor dot org
2012-11-07 14:31 ` jakub at gcc dot gnu.org
2012-11-07 14:45 ` andi-gcc at firstfloor dot org
2012-11-09 14:06 ` andi-gcc at firstfloor dot org
2012-11-09 15:24 ` ak at gcc dot gnu.org
2024-04-09  3:22 ` 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).