public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/109407] New: instruction cmpxchgl run error when using with g++ -O
@ 2023-04-04 15:37 johgjc at yeah dot net
2023-04-04 15:55 ` [Bug tree-optimization/109407] " pinskia at gcc dot gnu.org
2023-04-06 9:08 ` johgjc at yeah dot net
0 siblings, 2 replies; 3+ messages in thread
From: johgjc at yeah dot net @ 2023-04-04 15:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109407
Bug ID: 109407
Summary: instruction cmpxchgl run error when using with g++ -O
Product: gcc
Version: 9.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: johgjc at yeah dot net
Target Milestone: ---
Created attachment 54810
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54810&action=edit
a simple test code
the following code,
when using g++ test.cpp, the a.out is a endless loop as expected.
when using g++ -O2 test.cpp, the a.out returns and prints dwOriV=8
#include<cstdint>
#include<cstdio>
int main(){
volatile int dwOriV = 32;
int8_t dwRtnV = 0;
int dwExpV = 16;
int dwDstV = 8;
while(true){
__asm__ __volatile__(
"lock;"
"cmpxchgl %[NEW_VALUE], %[DST];"
"sete %[RET];"
: [RET] "=q"(dwRtnV),[DST] "+m"(dwOriV)
:[NEW_VALUE] "r"(dwDstV), "a"(dwExpV)
: "memory", "cc"
);
if(dwRtnV) {break;}
}
printf("%d",dwOriV);
return 0;
}
my gcc version:
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/109407] instruction cmpxchgl run error when using with g++ -O
2023-04-04 15:37 [Bug tree-optimization/109407] New: instruction cmpxchgl run error when using with g++ -O johgjc at yeah dot net
@ 2023-04-04 15:55 ` pinskia at gcc dot gnu.org
2023-04-06 9:08 ` johgjc at yeah dot net
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-04 15:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109407
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The inline-asm is incorrect as the EAX/RAX register gets clobbered by cmpxchgl
So you need something like (which works now):
int tmp;
__asm__ __volatile__(
"lock;"
"cmpxchgl %[NEW_VALUE], %[DST];"
"sete %[RET];"
: [RET] "=q"(dwRtnV),[DST] "+m"(dwOriV)
, "=a"(tmp) // newly added
:[NEW_VALUE] "r"(dwDstV), "a"(dwExpV)
: "memory", "cc"
);
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/109407] instruction cmpxchgl run error when using with g++ -O
2023-04-04 15:37 [Bug tree-optimization/109407] New: instruction cmpxchgl run error when using with g++ -O johgjc at yeah dot net
2023-04-04 15:55 ` [Bug tree-optimization/109407] " pinskia at gcc dot gnu.org
@ 2023-04-06 9:08 ` johgjc at yeah dot net
1 sibling, 0 replies; 3+ messages in thread
From: johgjc at yeah dot net @ 2023-04-06 9:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109407
--- Comment #2 from johgjc <johgjc at yeah dot net> ---
thank you very much.
At 2023-04-04 23:55:25, "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
wrote:
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109407
>
>Andrew Pinski <pinskia at gcc dot gnu.org> changed:
>
> What |Removed |Added
>----------------------------------------------------------------------------
> Resolution|--- |INVALID
> Status|UNCONFIRMED |RESOLVED
>
>--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>The inline-asm is incorrect as the EAX/RAX register gets clobbered by cmpxchgl
>So you need something like (which works now):
>
>int tmp;
>__asm__ __volatile__(
> "lock;"
> "cmpxchgl %[NEW_VALUE], %[DST];"
> "sete %[RET];"
> : [RET] "=q"(dwRtnV),[DST] "+m"(dwOriV)
> , "=a"(tmp) // newly added
> :[NEW_VALUE] "r"(dwDstV), "a"(dwExpV)
> : "memory", "cc"
>);
>
>--
>You are receiving this mail because:
>You reported the bug.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-06 9:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-04 15:37 [Bug tree-optimization/109407] New: instruction cmpxchgl run error when using with g++ -O johgjc at yeah dot net
2023-04-04 15:55 ` [Bug tree-optimization/109407] " pinskia at gcc dot gnu.org
2023-04-06 9:08 ` johgjc at yeah dot net
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).