[Bug tree-optimization/94293] [missed optimization] Useless statements populating local string not removed

2020-03-24 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293

--- Comment #8 from Andrew Pinski  ---
(In reply to Eyal Rozenberg from comment #6)
> (In reply to Richard Biener from comment #5)
> > DSE part  ... DCE
> 
> DSE = Dead Statement Elimination? DCE = Dead Code Elimination?

I thought Dse was dead store elimination.

[Bug tree-optimization/94293] [missed optimization] Useless statements populating local string not removed

2020-03-24 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293

--- Comment #7 from rguenther at suse dot de  ---
On Tue, 24 Mar 2020, eyalroz at technion dot ac.il wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293
> 
> --- Comment #6 from Eyal Rozenberg  ---
> (In reply to Richard Biener from comment #5)
> > DSE part  ... DCE
> 
> DSE = Dead Statement Elimination? DCE = Dead Code Elimination?

Exactly.

[Bug tree-optimization/94293] [missed optimization] Useless statements populating local string not removed

2020-03-24 Thread eyalroz at technion dot ac.il
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293

--- Comment #6 from Eyal Rozenberg  ---
(In reply to Richard Biener from comment #5)
> DSE part  ... DCE

DSE = Dead Statement Elimination? DCE = Dead Code Elimination?

[Bug tree-optimization/94293] [missed optimization] Useless statements populating local string not removed

2020-03-24 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293

Richard Biener  changed:

   What|Removed |Added

 CC||rguenth at gcc dot gnu.org
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2020-03-24
 Ever confirmed|0   |1
   Keywords||missed-optimization

--- Comment #5 from Richard Biener  ---
For the DSE part there's no operator delete handling in stmt_kills_ref_p.  The
clobber would need to be handled by DCE which is the one eliding new/delete
pairs.

Probably both are not too difficult to handle.

[Bug tree-optimization/94293] [missed optimization] Useless statements populating local string not removed

2020-03-23 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293

--- Comment #4 from Marc Glisse  ---
Or just

void f(){
  int*p=new int[1];
  *p=42;
  delete[] p;
}

while it does optimize for

void f(){
  int*p=new int;
  *p=42;
  delete p;
}

because the front-end gives us a clobber before operator delete.

[Bug tree-optimization/94293] [missed optimization] Useless statements populating local string not removed

2020-03-23 Thread eyalroz at technion dot ac.il
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293

--- Comment #3 from Eyal Rozenberg  ---
(In reply to Marc Glisse from comment #1)

You should probably post that comment on the second, related, bug 94294 - which
is about the fact that GCC keeps the new and delete. This one is strictly about
the population of the string, given that new and delete are called.

[Bug tree-optimization/94293] [missed optimization] Useless statements populating local string not removed

2020-03-23 Thread eyalroz at technion dot ac.il
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293

--- Comment #2 from Eyal Rozenberg  ---
Note:

The bugs also manifest with this slightly simpler program:


#include 

int bar() {
std::string second { "Hey... no small-string optimization for me please!"
};
return 123;
}

See: https://godbolt.org/z/LjmNYi

[Bug tree-optimization/94293] [missed optimization] Useless statements populating local string not removed

2020-03-23 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94293

--- Comment #1 from Marc Glisse  ---
Adding

inline void* operator new(std::size_t n){return __builtin_malloc(n);}
inline void operator delete(void*p)noexcept{__builtin_free(p);}
inline void operator delete(void*p,std::size_t)noexcept{__builtin_free(p);}

lets gcc optimize. Without it, we end up with

  _37 = operator new (51);
  __builtin_memcpy (_37, "Hey... no small-string optimization for me please!",
50);
  MEM[(char_type &)_37 + 50] = 0;
  operator delete (_37, 51);
  return 123;

I expect DSE (via tree-ssa-alias.c) doesn't know about delete the way it knows
about free and thus doesn't see the stores as dead.