public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: Stefan Franke <stefan@franke.ms>
Cc: gcc-help@gcc.gnu.org
Subject: Re: AW: C and C++ parser performing optimizations
Date: Tue, 4 Aug 2020 10:13:12 +0300 (MSK)	[thread overview]
Message-ID: <alpine.LNX.2.20.13.2008041009540.2454@monopod.intra.ispras.ru> (raw)
In-Reply-To: <000301d66a2a$ad8dcb50$08a961f0$@franke.ms>

On Tue, 4 Aug 2020, Stefan Franke wrote:

> Here is an example where gcc creates wrong code:
> 
> test.c:
> int foo() {
>   const char * const txt = "hello";
>   register const char * const p asm("ecx") = txt;
>   register int dx asm("edx");
>   asm(" call _faa" :"=r" (dx) :"rf" (p));
> }
> 
> gcc -O1 -S test.c -fdump-tree-original
> 
> The variable p gets replaced and the asm input parameters are wrong:
> 
> __asm__(" call _faa":"=r" dx:"rf" (const char * const) "hello");

I think it's a separate issue: even if the frontend wouldn't do such
propagation, I'm pretty sure later passes would. const and volatile
qualifiers just do not work as expected with register variables, and
since recently the documentation mentions that:

6.47.5.2 Specifying Registers for Local Variables

Do not use type qualifiers such as const and volatile, as the outcome may be
contrary to expectations. In particular, when the const qualifier is used, the
compiler may substitute the variable with its initializer in asm statements,
which may cause the corresponding operand to appear in a different register. 


6.47.5.1 Defining Global Register Variables

Do not use type qualifiers such as const and volatile, as the outcome may be
contrary to expectations. In particular, using the volatile qualifier does not
fully prevent the compiler from optimizing accesses to the register. 

  reply	other threads:[~2020-08-04  7:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-02 18:15 Stefan Franke
2020-08-02 18:40 ` Alexander Monakov
2020-08-04  6:44   ` AW: " Stefan Franke
2020-08-04  7:13     ` Alexander Monakov [this message]
2020-08-04 15:33       ` Segher Boessenkool
2020-08-24 19:06     ` Gunther Nikl
2020-08-24 19:54       ` AW: " Stefan Franke

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.2008041009540.2454@monopod.intra.ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=gcc-help@gcc.gnu.org \
    --cc=stefan@franke.ms \
    /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).