public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Bingfeng Mei" <bmei@broadcom.com>
To: "Richard Guenther" <richard.guenther@gmail.com>
Cc: "Andrew Haley" <aph@redhat.com>, 	"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: RE: Release novops attribute for external use?
Date: Tue, 13 Apr 2010 10:23:00 -0000	[thread overview]
Message-ID: <7FB04A5C213E9943A72EE127DB74F0ADA66512E938@SJEXCHCCR02.corp.ad.broadcom.com> (raw)
In-Reply-To: <r2t84fc9c001004130245ja897b182ne58cfe2ed103f517@mail.gmail.com>

> 
> Surely printf writes to global memory (it clobbers the stdout FILE*)
> 
OK, the point is not about whether printf is pure or not. Instead, if
programmer knows the callee function such as printf contains no 
memory access that affects operations inside caller function, and he
would like to have a way to optimize the code. Our engineer gave following
example: 

    void myfunc(MyStruct *myStruct)
    {
      int a,b;
      a = myStruct->a;
      printf("a=%d\n",a);
      b = 2*mystruct->a;      // I would like to have the compiler acting as if I had written b = 2*a;
     ...
    }
Providing such attribute may be potentially dangerous. But it is just
like "restrict" qualifier and some other attributes, putting responsibilty
of correctness on the programmer. "novops" seems to achieve that effect, 
though its semantics doesn't match exactly what I described. 


> As for the original question - novops is internal only because its
> semantics is purely internal and changes with internal aliasing
> changes.
> 
> Now, we still lack a compelling example to see what exact semantics
> you are requesting?  I suppose it might be close to a pure but
> volatile function?  Which you could simulate by
> 
> dummy = pure_fn ();
> asm ("" : "g" (dummy));
> 
> or even
> 
> volatile int dummy = pure_fn ();

These two methods still generate extra code to reload variables

Bingfeng


> 
> Richard.
> 
> > Bingfeng
> >
> >> -----Original Message-----
> >> From: gcc-owner@gcc.gnu.org [mailto:gcc-owner@gcc.gnu.org] On
> >> Behalf Of Andrew Haley
> >> Sent: 12 April 2010 17:34
> >> To: gcc@gcc.gnu.org
> >> Subject: Re: Release novops attribute for external use?
> >>
> >> On 04/12/2010 05:27 PM, Bingfeng Mei wrote:
> >> > Hello,
> >> > One of our engineers requested a feature so that
> >> > compiler can avoid to re-load variables after a function
> >> > call if it is known not to write to memory. It should
> >> > slash considerable code size in our applications. I found
> >> > the existing "pure" and "const" cannot meet his requirements
> >> > because the function is optimized out if it doesn't return
> >> > a value.
> >>
> >> If a function doesn't write to memory and it doesn't return a
> >> value, what is the point of calling it?
> >>
> >> Andrew.
> >>
> >>
> >
> 
> 

  parent reply	other threads:[~2010-04-13 10:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-12 16:56 Bingfeng Mei
2010-04-12 16:58 ` Andrew Haley
2010-04-12 18:05   ` Dave Korn
2010-04-12 18:10     ` Andrew Haley
2010-04-12 18:29       ` Dave Korn
2010-04-12 20:53         ` Daniel Jacobowitz
2010-04-13  9:45   ` Bingfeng Mei
2010-04-13  9:56     ` Richard Guenther
2010-04-13 10:15       ` Andrew Haley
2010-04-13 10:23       ` Bingfeng Mei [this message]
2010-04-13 10:25         ` Richard Guenther
2010-04-13 10:57           ` Richard Guenther
2010-04-13 11:35             ` Bingfeng Mei
2010-04-13 11:53           ` Manuel López-Ibáñez
2010-04-13 15:06             ` Richard Guenther

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=7FB04A5C213E9943A72EE127DB74F0ADA66512E938@SJEXCHCCR02.corp.ad.broadcom.com \
    --to=bmei@broadcom.com \
    --cc=aph@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=richard.guenther@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).