[PATCH] D14148: [GlobalOpt] Demote globals to locals more aggressively

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 07:49:30 PST 2015


Hi,

> On Nov 16, 2015, at 2:39 AM, James Molloy <james.molloy at arm.com> wrote:
> 
> jmolloy added a comment.
> 
> Hi All,
> 
> I just want to apologize - after rereading the phab comments here I realize that I actually mistook Mehdi's LGTM on http://reviews.llvm.org/D14228 for this review when looking at my backlog, so I committed it before it was fully approved.
> 
> To reply to Mehdi's comment specifically:
> 
>> If the function does not recurse and is the only user of the global, why do we need isPointerValueDeadOnEntryToFunction?
> 
> 
> Consider this:
> 
>  static int g = 0;
>  int f() {
>    printf("%d\n", g++);
>  }
> 
> ``g`` can obviously not be localized, and ``f`` does not recurse. However, each invocation of ``f`` depends on the previous invocation because ``g`` is read before being written. The "isPointerValueDeadOnEntry" function is there to ensure the function is idempotent with respect to the given global.
> 


Makes sense, I was sure I knew the reason but I forgot about this…
So there will be cases where we will regress in the optimization for “main()”, when we can’t prove that the pointer is dead on entry. I don’t think it really matters that much in practice though, but it may look bad on some benchmarks.

Thanks,

— 
Mehdi


More information about the llvm-commits mailing list