[Bug middle-end/93644] [10 Regression] spurious -Wreturn-local-addr with PHI of PHI

2020-02-19 Thread law at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644

Jeffrey A. Law  changed:

   What|Removed |Added

   Priority|P3  |P2
   Target Milestone|10.0|11.0

[Bug middle-end/93644] [10 Regression] spurious -Wreturn-local-addr with PHI of PHI

2020-02-19 Thread law at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644

--- Comment #7 from Jeffrey A. Law  ---
So optimizing things in remove_range_assertions works for the reduced testcase,
but not for the original testcase.  There's a couple of deeper issues that have
to be figured out for the original testcase. 

The trick we were trying to utilize is if we could safely copy-propagate a
value which we knew not to be a stack address for an object which might have
been a stack address, then we avoid the false positive.  This has a nice
property that it likely improves optimization.

But it's insufficient for the full testcase.  First, loops get in the way. 

We might have something like this at the top of a loop:


x = phi (a, b)
b = 


If we have an subsequent assert that x != b, we can't then replace uses of x
with a.  Why?  Because the assert refers to the value of b on the current
iteration while the PHI refers to the value of b on the previous iteration. 
This issue doesn't show up in the reduced testcase, but does in the full
testcase.

Second, we have to deal with the cascading nature of the asserts.  If we go
back to the original testcase the PHI in question looks like this just before
removal of the ASSERT_EXPRs in VRP1:

  # _25 = PHI <0B(10), buf_79(16), 0B(26), 0B(30), b_94(15), b_92(19), 0B(9),
buf_80(17), buf_80(39)>

Just looking at chain for buf_79 we have:

  # buffer_17 = PHI <_buf(5), buffer_38(D)(34)>

  # buf_20 = PHI 

  # buf_29 = PHI 

  buf_79 = ASSERT_EXPR ;


We can see that buf_79 has 3 possible values:

_buf, buffer_38 and buf_90 (buf_90 is loop carried)

The ASSERT only excludes _buf so we can't copy propagate buffer_38 or
buf_90 for the uses of buf_79.  And we (of course) lose the knowledge that
buf_79 can't be _buf when we drop the ASSERT_EXPRs.


We may still want to use the trick Marc noted in c#2.  It applies something
like 20k times during a bootstrap and fixes Wreturn-local-addr-9 in the
testsuite.  But it doesn't seem appropriate for stage4.

I find myself wondering if we could tackle this on the alias analysis side by
looking at the PTA solution and see if any of the objects point into the stack.
 I also wonder if PTA would benefit from the VRP analysis which excluded the
stack object for certain addresses.  All blue sky stuff though.

[Bug middle-end/93644] [10 Regression] spurious -Wreturn-local-addr with PHI of PHI

2020-02-10 Thread law at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644

--- Comment #6 from Jeffrey A. Law  ---
I think we might be able to do this in remove_range_assertions

[Bug middle-end/93644] [10 Regression] spurious -Wreturn-local-addr with PHI of PHI

2020-02-10 Thread law at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644

Jeffrey A. Law  changed:

   What|Removed |Added

 CC||law at redhat dot com

--- Comment #5 from Jeffrey A. Law  ---
WRT c#2, yes it's a reasonable deduction, but the warning and the point where
we have the asserts are in two different passes.  ie, the info isn't really
available when we need it.



What we might be able to do is see the assert:

  buffer_16 = ASSERT_EXPR ;

Then look at the DEF point for buffer_3:

  # buffer_3 = PHI <_buf(3), buffer_8(D)(9)>

Which means at the point of the assertion that buffer_16 can only have the
value buffer_8 and replace the assert with

buffer_16 = buffer_8

That would in turn allow the use of buffer_16 in the problematic PHI to be
replaced with buffer_8 and avoid the problem

We have to be careful and ensure that doesn't break the SSA form (it's safe in
this example because buffer_8 is the default def).

[Bug middle-end/93644] [10 Regression] spurious -Wreturn-local-addr with PHI of PHI

2020-02-10 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |10.0