public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/58782] New: GCC generates unnecessary _ITM_WU8 for local variables.
@ 2013-10-18 9:14 srdjan.stipic at gmail dot com
2013-10-18 9:22 ` [Bug c/58782] " jakub at gcc dot gnu.org
2013-10-18 12:15 ` srdjan.stipic at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: srdjan.stipic at gmail dot com @ 2013-10-18 9:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58782
Bug ID: 58782
Summary: GCC generates unnecessary _ITM_WU8 for local
variables.
Product: gcc
Version: trans-mem
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: srdjan.stipic at gmail dot com
Created attachment 31031
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31031&action=edit
Minimal test case.
GCC generates unnecessary_ITM_WU8 for local variables.
Example:
typedef struct {
void* firstPtr;
void* secondPtr;
} pair_t;
__attribute__((transaction_safe)) list_find(void*, void*);
void* list_find_helper (void* listPtr, void* keyPtr) {
pair_t findPair;
findPair.firstPtr = keyPtr; // the _ITM_WU8() is generated here
// but is unnecessary because findPair is local
list_find(listPtr, &findPair);
return findPair.secondPtr;
}
Compiled with 4.7.3 -O3 -fgnu-tm
Generated code for transactional clone:
_ZGTt16list_find_helperPvS_:
pushq %rbx
movq %rdi, %rbx
subq $16, %rsp
movq %rsp, %rdi
call _ITM_WU8 // unnecessary write
movq %rsp, %rsi
movq %rbx, %rdi
call _ZGTt9list_findPvS_
leaq 8(%rsp), %rdi
call _ITM_RU8
addq $16, %rsp
popq %rbx
ret
P.S.
This is the example on gcc.godbolt.org:
http://gcc.godbolt.org/#%7B%22version%22%3A3%2C%22filterAsm%22%3A%7B%22labels%22%3Atrue%2C%22directives%22%3Atrue%2C%22commentOnly%22%3Atrue%7D%2C%22compilers%22%3A%5B%7B%22source%22%3A%22typedef%20struct%20%7B%5Cn%20%20void*%20firstPtr%3B%5Cn%20%20void*%20secondPtr%3B%5Cn%7D%20pair_t%3B%5Cn%5Cn__attribute__((transaction_safe))%20void*%20list_find(void*%2C%20void*)%3B%5Cn%5Cn__attribute__((noinline))%5Cnvoid*%20list_find_helper%20(void*%20listPtr%2C%20void*%20keyPtr)%20%7B%5Cn%20%20pair_t%20findPair%3B%5Cn%5Cn%20%20findPair.firstPtr%20%3D%20keyPtr%3B%5Cn%20%20%20%20%5Cn%20%20list_find(listPtr%2C%20%26findPair)%3B%5Cn%20%20return%20findPair.secondPtr%3B%5Cn%7D%5Cn%5Cn%5Cnvoid*%20TMlist_find%20(void*%20hashtablePtr%2C%20void*%20keyPtr)%20%7B%5Cn%20%20void*%20ret%3B%5Cn%20%20__transaction_atomic%20%7B%5Cn%20%20%20%20ret%20%3D%20list_find_helper(hashtablePtr%2C%20keyPtr)%3B%5Cn%20%20%7D%5Cn%20%20return%20ret%3B%5Cn%7D%22%2C%22compiler%22%3A%22%2Fusr%2Fbin%2Fg%2B%2B-4.7%22%2C%22options%22%3A%22-O3%20-fgnu-tm%22%7D%5D%7D
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/58782] GCC generates unnecessary _ITM_WU8 for local variables.
2013-10-18 9:14 [Bug c/58782] New: GCC generates unnecessary _ITM_WU8 for local variables srdjan.stipic at gmail dot com
@ 2013-10-18 9:22 ` jakub at gcc dot gnu.org
2013-10-18 12:15 ` srdjan.stipic at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-10-18 9:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58782
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It is local, but address taken, and the address may escape to other threads.
In this testcase that isn't a problem, because the store happens before the
address is taken, but that would require extra analysis - address taken
automatic variables are not in SSA form and the flag that it is addressable is
just a global flag.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/58782] GCC generates unnecessary _ITM_WU8 for local variables.
2013-10-18 9:14 [Bug c/58782] New: GCC generates unnecessary _ITM_WU8 for local variables srdjan.stipic at gmail dot com
2013-10-18 9:22 ` [Bug c/58782] " jakub at gcc dot gnu.org
@ 2013-10-18 12:15 ` srdjan.stipic at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: srdjan.stipic at gmail dot com @ 2013-10-18 12:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58782
--- Comment #2 from Srdjan Stipic <srdjan.stipic at gmail dot com> ---
Hi Jakub.
> In this testcase that isn't a problem, because the store happens before the
> address is taken, but that would require extra analysis
This is the reason why I submitted the bug.
I expected that gcc would eliminate unnecessary writes
until the address is taken.
Here is the case when the address is not taken but gcc generates
unnecessary _ITM_WU4():
void* f(int x) {
int* out;
out = (int*)malloc(sizeof(int));
*out = x;
return out;
}
_ZGTt1fi:
movq %rbx, -16(%rsp)
movq %rbp, -8(%rsp)
subq $24, %rsp
movl %edi, %ebp
movl $4, %edi
call _ITM_malloc
movl %ebp, %esi
movq %rax, %rbx
movq %rax, %rdi
call _ITM_WU4
movq %rbx, %rax
movq 16(%rsp), %rbp
movq 8(%rsp), %rbx
addq $24, %rsp
ret
Why gcc generates _ITM_WU4 when the address is not taken?
(I can see that 'out' escapes)
Cheers,
Srdjan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-10-18 12:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-18 9:14 [Bug c/58782] New: GCC generates unnecessary _ITM_WU8 for local variables srdjan.stipic at gmail dot com
2013-10-18 9:22 ` [Bug c/58782] " jakub at gcc dot gnu.org
2013-10-18 12:15 ` srdjan.stipic at gmail dot com
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).