This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: missed PTA optimization?


Am Dienstag, den 11.02.2020, 21:43 +0100 schrieb Richard Biener:
> On February 11, 2020 9:32:14 PM GMT+01:00, "Uecker, Martin" <Martin.Uecker@med.uni-goettingen.de>
> wrote:
> > 
> > In the following example, it seems
> > that 'bar' could be optimized to
> > return '1' and every else could be
> > optimized away. Or am I missing
> > something?   
> 
> p might be still NULL when bar is called. 
> 
> > Do I need to add
> > some specific compiler flags?
> 
> -fipa-pta 

This does not appear to change anything. Also
if I initialize p to the address of 'a', this
changes nothing. 

For the second function, I get:

p = { ESCAPED NONLOCAL }

> But we simply do not implement turning pointer dereference into direct accesses when points to
> says it would be possible. And yes, the NULL case can probably be ignored (though we generally
> support catching NULL dereferences with signal handlers), or at least speculated away with a well
> predicted branch. 
> 
> Any situation where doing the above is profitable? 

No, just trying to understand what is happening.
(clang does this optimization).

Best,
Martin

> > 
> > 
> > static int a = 1;
> > static int *p;
> > 
> > extern
> > void foo(void)
> > {
> >   p = &a;
> > }
> > 
> > extern
> > int bar(void)
> > {
> >   return *p;
> > }
> > 
> > 
> > thank you,
> > Martin
> 
> 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]