[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2018-05-11 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #13 from rguenther at suse dot de  ---
On Fri, 11 May 2018, glisse at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617
> 
> --- Comment #12 from Marc Glisse  ---
> (In reply to Richard Biener from comment #11)
> > Dup of PR23094 (and fixed).
> 
> Richard, comment #9 shows that the original testcase is only half-fixed 
> (though
> the other half seems hard to fix). Does this mean you consider the second half
> as WONTFIX?

So ...

  __old_val_5 = MEM[(void * &)a_2(D)];
  MEM[(void * &)a_2(D)] = 0B;
  __old_val_6 = MEM[(void * &)b_3(D)];
  MEM[(void * &)b_3(D)] = 0B;
  MEM[(void * &)a_2(D)] = __old_val_6;
  _7 = MEM[(void * &)b_3(D)];
  MEM[(void * &)b_3(D)] = __old_val_5;
  if (_7 != 0B)

.. the logic is that if a and b alias they have to exactly overlap
and thus _7 is __old_val_6 which is then 0.

While it might be quite interesting to try considering this
it requires a bit too much magic for the current machinery ;)
We've already value-numbered __old_val_6 but we would need to
re-visit its def with the constraint a_2 == b_3 so this would
add some back-propagation to the forward-working value-numbering.

The PR23094 fix is already somewhat limited and I'm not holding
my breath on the above given it doesn't fit any existing
optimization algorithm very well...  (complexity also explodes
once you need to consider any combination of exact-overlap
aliases).

We can re-open this to track the issue.

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2018-05-11 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #12 from Marc Glisse  ---
(In reply to Richard Biener from comment #11)
> Dup of PR23094 (and fixed).

Richard, comment #9 shows that the original testcase is only half-fixed (though
the other half seems hard to fix). Does this mean you consider the second half
as WONTFIX?

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2018-05-11 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

Richard Biener  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #11 from Richard Biener  ---
Dup of PR23094 (and fixed).

*** This bug has been marked as a duplicate of bug 23094 ***

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2018-05-10 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement

--- Comment #10 from Andrew Pinski  ---
(In reply to Marc Glisse from comment #9)
> The testcases from comment #6 and comment #7 are now (gcc-8) properly
> optimized. The original has lost one of the 2 calls to free, one remains:
> 
>  __old_val_4 = MEM[(void * &)a_2(D)];
>   MEM[(void * &)a_2(D)] = 0B;
>   __old_val_5 = MEM[(void * &)b_3(D)];
>   MEM[(void * &)b_3(D)] = 0B;
>   MEM[(void * &)a_2(D)] = __old_val_5;
>   _6 = MEM[(void * &)b_3(D)];
>   MEM[(void * &)b_3(D)] = __old_val_4;
>   if (_6 != 0B)
> 
> (whether a is the same as b or disjoint, _6 is always 0, but that's not easy
> to see)

Do to the above analysis, there is another bug which this is a dup of but I
can't find it right now.

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2018-05-10 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #9 from Marc Glisse  ---
The testcases from comment #6 and comment #7 are now (gcc-8) properly
optimized. The original has lost one of the 2 calls to free, one remains:

 __old_val_4 = MEM[(void * &)a_2(D)];
  MEM[(void * &)a_2(D)] = 0B;
  __old_val_5 = MEM[(void * &)b_3(D)];
  MEM[(void * &)b_3(D)] = 0B;
  MEM[(void * &)a_2(D)] = __old_val_5;
  _6 = MEM[(void * &)b_3(D)];
  MEM[(void * &)b_3(D)] = __old_val_4;
  if (_6 != 0B)

(whether a is the same as b or disjoint, _6 is always 0, but that's not easy to
see)

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2017-06-25 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #8 from Andrew Pinski  ---
(In reply to Richard Biener from comment #6)
> C testcase:

I have seen that testcase before in a bug report but I can't find the bug
report  :(.

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2017-05-04 Thread herring at lanl dot gov
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #7 from S. Davis Herring  ---
We can extend the C test case (thanks for that) with a shared, non-constant
value (and more savings by having dead code as in the original C++ example):

void foo(int *p,int *q,int x) {
  *q=*p=x;
  if(*p!=x) abort();  /* dead */
}

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2017-05-04 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #6 from Richard Biener  ---
C testcase:

int foo (int *p, int *q)
{
  *p = 1;
  *q = 1;
  return *p;
}

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2017-05-04 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

Richard Biener  changed:

   What|Removed |Added

 Status|WAITING |NEW

--- Comment #5 from Richard Biener  ---
So we end up with

void disassemble_me(A&, A&) (struct A & a, struct A & b)
{
  void * __old_val;
  void * __old_val;
  void * _7;
  void * _8;

   [100.00%]:
  __old_val_5 = MEM[(void * &)a_2(D)];
  MEM[(void * &)a_2(D)] = 0B;
  __old_val_6 = MEM[(void * &)b_3(D)];
  MEM[(void * &)b_3(D)] = 0B;
  _7 = MEM[(void * &)a_2(D)];
  MEM[(void * &)a_2(D)] = __old_val_6;
  if (_7 != 0B)
goto ; [53.47%]
  else
goto ; [46.53%]

   [53.47%]:
  free (_7);
...

which shows this issue.  I believe there's a duplicate PR for this somewhere...
(I even remember writing a patch for this).

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2017-05-04 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #4 from Marc Glisse  ---
  MEM[(void * &)a_2(D)] = 0B;
  MEM[(void * &)b_3(D)] = 0B;
  _7 = MEM[(void * &)a_2(D)];

Indeed.

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2017-05-04 Thread herring at lanl dot gov
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #3 from S. Davis Herring  ---
Created attachment 41314
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41314=edit
bad assembly test case

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2017-05-04 Thread herring at lanl dot gov
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

--- Comment #2 from S. Davis Herring  ---
So sorry.  For whatever reason, copy/paste works for me thence...

#include
#include
#include

struct A {  // vaguely unique_ptr-like
  void *p;
  A(A &) : p(a.release()) {}
  ~A() {if(p) std::free(p);}// not that you can't free(nullptr)
  void* release() {return std::exchange(p,nullptr);}
  void swap(A ) {std::swap(p,a.p);}
  A& operator=(A &) {A(std::move(a)).swap(*this); return *this;}
};

void disassemble_me(A ,A ) {std::swap(a,b);}

int main() {
  return !!execlp("cat","cat","prog.s",static_cast(0));
}

[Bug tree-optimization/80617] [missed optimization] Storing constant in two possibly-aliased locations

2017-05-04 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80617

Richard Biener  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2017-05-04
 CC||rguenth at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
Can you please attach the whole example?  One can't cut from this stupid
web page.