public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/57742] memset(malloc(n),0,n) -> calloc(n,1)
Date: Tue, 15 Oct 2013 07:57:00 -0000	[thread overview]
Message-ID: <bug-57742-4-eyw4aqvR4G@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57742-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57742

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #7)
> (In reply to Richard Biener from comment #5)
> > We have walk_aliased_vdefs for this.  Basically the first callback
> > you receive has to be the malloc, otherwise there is an aliasing
> > stmt inbetween.  Initialize the ao_ref with ao_ref_init_from_ptr_and_size.
> 
> Hmm, there is a problem with that: I don't get a callback for malloc.
> stmt_may_clobber_ref_p_1 only looks at the lhs of a call statement if it
> isn't an SSA_NAME, so it considers that p=malloc(n) does not clobber
> MEM_REF[p]. This kind of makes sense, it creates this memory, which is
> different from clobbering. I can look at the def_stmt of the first argument
> of memset to find the malloc, at least, but that doesn't help me with the
> memory checks.
> 
> Also, for this testcase:
> void* f(int n,double*d){
>   int* p=__builtin_malloc(n);
>   ++*d;
>   __builtin_memset(p,0,n);
>   return p;
> }
> I actually get a callback for the store in *d, which gcc believes might
> alias :-(

Yeah well, either because of pass placement or because of points-to
analysis being not context sensitive.

> For this example:
> void g(int*);
> void* f(int n){
>   int* p=__builtin_malloc(n);
>   for(int i=0;i<10000;++i){
>     __builtin_memset(p,0,n);
>     g(p);
>     p[5]=10;
>   }
>   return p;
> }
> if I modify the aliasing machinery to make it believe that p=malloc does
> alias, malloc is the first callback. I haven't added the dominance checks,
> but I assume they will tell me that malloc dominates memset and memset
> postdominates malloc, although I still shouldn't do the transformation.
> 
> Pretty depressed at this point...

Nobody said it was going to be trivial ;)

Exact pattern matching of the CFG involved might be the easiest, plus
manually implementing walk_aliased_vdefs by simply walking the use-def
chain of the virtual operands from the memset operation to the malloc
and checking stmt_may_clobber_ref_p_1 on the ao_ref_init_from_ptr_and_size
ref.


  parent reply	other threads:[~2013-10-15  7:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27 22:28 [Bug tree-optimization/57742] New: " glisse at gcc dot gnu.org
2013-10-11 16:44 ` [Bug tree-optimization/57742] " glisse at gcc dot gnu.org
2013-10-14  8:55 ` rguenth at gcc dot gnu.org
2013-10-14  9:51 ` Joost.VandeVondele at mat dot ethz.ch
2013-10-14 10:07 ` glisse at gcc dot gnu.org
2013-10-14 10:46 ` rguenth at gcc dot gnu.org
2013-10-14 11:48 ` glisse at gcc dot gnu.org
2013-10-14 20:51 ` glisse at gcc dot gnu.org
2013-10-14 20:53 ` glisse at gcc dot gnu.org
2013-10-15  7:57 ` rguenth at gcc dot gnu.org [this message]
2013-10-15 14:11 ` glisse at gcc dot gnu.org
2013-10-15 16:38 ` glisse at gcc dot gnu.org
2013-10-16 14:11 ` rguenth at gcc dot gnu.org
2014-02-22 15:44 ` glisse at gcc dot gnu.org
2014-02-23 18:46 ` glisse at gcc dot gnu.org
2014-06-24 19:04 ` glisse at gcc dot gnu.org
2014-06-25  6:46 ` Joost.VandeVondele at mat dot ethz.ch
2014-06-25  7:41 ` Joost.VandeVondele at mat dot ethz.ch
2014-06-25  7:53 ` glisse at gcc dot gnu.org
2014-06-25  8:09 ` glisse at gcc dot gnu.org
2014-06-25 12:27 ` glisse at gcc dot gnu.org
2014-06-25 12:29 ` glisse at gcc dot gnu.org
2015-09-17 19:32 ` daniel.gutson at tallertechnologies dot com

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=bug-57742-4-eyw4aqvR4G@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).