public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: gcc-help@gcc.gnu.org
Subject: Re: Problem understand optimization with inline asm
Date: Tue, 28 Mar 2023 12:41:56 +0100	[thread overview]
Message-ID: <56c2aabe-dbac-60b1-1531-e1e222036633@redhat.com> (raw)
In-Reply-To: <CAJWNc-62ebOfM6E=z8H9h3vE=+qfss2kidaHpWH3usWLSO9iuA@mail.gmail.com>

On 3/28/23 12:15, Kalamatee via Gcc-help wrote:
> Now, I can work around this by using "+" (even though I don't read the
> variable), or initializing the value a second time in the asm block - but
> should I have to?

Yes.

> This sounds like the compiler is doing the wrong thing
> based on the assertion/assumption "=" means I will 100% change some
> variable,

That's what you've told GCC you will do. GCC doesn't look inside the asm
statement to see if you really do it.

> and worse after optimizing the code and creating a case where I
> now have an uninitialized variable being used - does not warn me this is
> happening?

You've told GCC that you initialized the variable, and GCC believes you.
If you lie to the compiler, it will get its revenge.

 > Would it not be better to interpret "=" to mean "may" change the value,
 > which would prevent it incorrectly optimizing the initialization away, or
 > if it does warn that the value may be used uninitialized?

If we did that we'd have to add another pattern which means "definitely
initialized". That would greatly complicate data flow analysis, for no
very good reason.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


  reply	other threads:[~2023-03-28 11:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 11:15 Kalamatee
2023-03-28 11:41 ` Andrew Haley [this message]
2023-03-28 11:44   ` Andrew Haley
2023-03-28 22:45 ` Segher Boessenkool

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=56c2aabe-dbac-60b1-1531-e1e222036633@redhat.com \
    --to=aph@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    /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).