From: Alexander Monakov <amonakov@ispras.ru>
To: "☂Josh Chia (謝任中)" <joshchia@gmail.com>
Cc: "Florian Weimer" <fweimer@redhat.com>,
"☂Josh Chia (謝任中) via Gcc-help" <gcc-help@gcc.gnu.org>
Subject: Re: Failure to optimize?
Date: Tue, 12 Jan 2021 17:15:59 +0300 (MSK) [thread overview]
Message-ID: <alpine.LNX.2.20.13.2101121711290.23548@monopod.intra.ispras.ru> (raw)
In-Reply-To: <CALxtSbQbPcG0r+wKn73peSaLMwV4fBYP6BWBw4aJL8K+Lygc+A@mail.gmail.com>
On Tue, 12 Jan 2021, ☂Josh Chia (謝任中) via Gcc-help wrote:
> I didn't mention it earlier, but I'd like to clarify that this is for "g++
> -O3 -std=c++17" on GCC 10.2.
>
> If I use "static thread_local int cursor = 0;" then cursor is thread-local
> and such a race should be impossible, but the generated code for bar1()
> still has a branch.
Whether 'cursor' is thread-local or not does not matter, it's possible to take
the address of a thread-local variable and pass it to another thread.
> The branch persists also if I do this instead for bar1():
> char const* bar1() {
> char const* result = foo();
> if (result)
> cursor += 1;
> else
> cursor += 0;
> return result;
> }
This is hard to optimize as 'cursor += 0' is optimized out quite early, and
it's hard to keep track that 'cursor' is unconditionally written in the
abstract machine.
Alexander
next prev parent reply other threads:[~2021-01-12 14:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 13:32 ☂Josh Chia (謝任中)
2021-01-12 13:36 ` Florian Weimer
2021-01-12 14:05 ` ☂Josh Chia (謝任中)
2021-01-12 14:15 ` Alexander Monakov [this message]
2021-01-12 14:20 ` Florian Weimer
2021-01-12 14:20 ` Jonathan Wakely
2021-01-12 14:22 ` Florian Weimer
2021-01-12 16:53 ` Liu Hao
2021-01-12 18:16 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LNX.2.20.13.2101121711290.23548@monopod.intra.ispras.ru \
--to=amonakov@ispras.ru \
--cc=fweimer@redhat.com \
--cc=gcc-help@gcc.gnu.org \
--cc=joshchia@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).