public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name
@ 2021-11-13  6:54 pinskia at gcc dot gnu.org
  2021-11-15  9:01 ` [Bug tree-optimization/103221] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-13  6:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103221

            Bug ID: 103221
           Summary: evrp removes |SIGN but does not propagate the ssa name
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
signed char f(signed char a)
{
  signed char v;
  v = a;
  if (a < 0)
    v = a | -128;
  return v;
}
---- CUT ----
EVRP is able to remove the | -128 part but still left with:
  if (a_2(D) < 0)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  v_4 = a_2(D);

  <bb 4> :
  # v_1 = PHI <a_2(D)(2), v_4(3)>
  return v_1;

But the PHI should be removed and the function should have been at this point
just "return a_2(D);".

Note this is not a regression and even the original VRP had a similar issue
too.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/103221] evrp removes |SIGN but does not propagate the ssa name
  2021-11-13  6:54 [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name pinskia at gcc dot gnu.org
@ 2021-11-15  9:01 ` rguenth at gcc dot gnu.org
  2021-11-23 20:20 ` amacleod at redhat dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-15  9:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103221

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-11-15
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
IIRC this is simplify_stmt_using_ranges not being applied during propagation
and thus the copy not being recorded.  At elimination time we are not recording
new equivalences.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/103221] evrp removes |SIGN but does not propagate the ssa name
  2021-11-13  6:54 [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name pinskia at gcc dot gnu.org
  2021-11-15  9:01 ` [Bug tree-optimization/103221] " rguenth at gcc dot gnu.org
@ 2021-11-23 20:20 ` amacleod at redhat dot com
  2021-11-25 15:21 ` amacleod at redhat dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: amacleod at redhat dot com @ 2021-11-23 20:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103221

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com

--- Comment #2 from Andrew Macleod <amacleod at redhat dot com> ---
I can tweak it so that we do register the equivalence with ranger by
reprocessing statements after a successful simplify or fold:

=========== BB 3 ============
a_2(D)  signed char [-INF, -1]
Equivalence set : [a_2(D), v_4]
    <bb 3> :
    v_4 = a_2(D);

v_4 : signed char [-INF, -1]

=========== BB 4 ============
    <bb 4> :
    # v_1 = PHI <a_2(D)(2), v_4(3)>

but it doesn't buy us much on its own.

Later passes propagate a_2 into the PHI and then fold the PHI into a copy
regardless.

We could in theory do that in EVRP too, but it seems like something copy
propagation or PHI-opt would handle more naturally.  The arguments can come
from an arbitrary list of equivalences and yet resolve to the same value... but
we need to pick the right one.  

That said, its probably worth getting the equivalence added because that could
be useful in other ways too.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/103221] evrp removes |SIGN but does not propagate the ssa name
  2021-11-13  6:54 [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name pinskia at gcc dot gnu.org
  2021-11-15  9:01 ` [Bug tree-optimization/103221] " rguenth at gcc dot gnu.org
  2021-11-23 20:20 ` amacleod at redhat dot com
@ 2021-11-25 15:21 ` amacleod at redhat dot com
  2021-12-25  9:59 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: amacleod at redhat dot com @ 2021-11-25 15:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103221

--- Comment #3 from Andrew Macleod <amacleod at redhat dot com> ---
And BTW, we do this optimization, just not completely in evrp.  EVRP removes
the extraneous | -128 since that is a range related action.

Constant propagation handles the propagation of the copy into the PHI, I'm not
sure we also need to do it in a VRP pass.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/103221] evrp removes |SIGN but does not propagate the ssa name
  2021-11-13  6:54 [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-11-25 15:21 ` amacleod at redhat dot com
@ 2021-12-25  9:59 ` pinskia at gcc dot gnu.org
  2022-01-12 20:45 ` amacleod at redhat dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-25  9:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103221

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 77893 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/103221] evrp removes |SIGN but does not propagate the ssa name
  2021-11-13  6:54 [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-12-25  9:59 ` pinskia at gcc dot gnu.org
@ 2022-01-12 20:45 ` amacleod at redhat dot com
  2022-01-12 20:52 ` pinskia at gcc dot gnu.org
  2022-01-12 20:59 ` amacleod at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: amacleod at redhat dot com @ 2022-01-12 20:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103221

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #5 from Andrew Macleod <amacleod at redhat dot com> ---
We perform this optimization in appropriate places.

EVRP uses ranges to remove the | -128 leaving the statement as a copy.

Although we could then propagate the copy into the PHI node, I think we should
leave that to the copy propagation and PHIOPT passes, as we could also make
poor decisions since we are doing it with no context. 

EVRP is enabling the other passes to do their job, and GCC turns this into
"return a" as expected.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/103221] evrp removes |SIGN but does not propagate the ssa name
  2021-11-13  6:54 [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-01-12 20:45 ` amacleod at redhat dot com
@ 2022-01-12 20:52 ` pinskia at gcc dot gnu.org
  2022-01-12 20:59 ` amacleod at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-12 20:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103221

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |WONTFIX

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This bug was asking explictly for evpr to do that. So closing as won't fix
then.
The reasoning why I filed this bug is because between evrp and phiopt1 there is
not a copy prop pass.  The next copy prop pass is not until after inlining so
we might not inline as much either. So either we need to reorder some passes
around or add a copy prop pass sooner.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/103221] evrp removes |SIGN but does not propagate the ssa name
  2021-11-13  6:54 [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name pinskia at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-01-12 20:52 ` pinskia at gcc dot gnu.org
@ 2022-01-12 20:59 ` amacleod at redhat dot com
  6 siblings, 0 replies; 8+ messages in thread
From: amacleod at redhat dot com @ 2022-01-12 20:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103221

--- Comment #7 from Andrew Macleod <amacleod at redhat dot com> ---
We probably do need to revisit some pass ordering.  I hope to do even less
propagation within the VRPs next release, so I would expect running copyprop
afterwards would be worthwhile.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-01-12 20:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-13  6:54 [Bug tree-optimization/103221] New: evrp removes |SIGN but does not propagate the ssa name pinskia at gcc dot gnu.org
2021-11-15  9:01 ` [Bug tree-optimization/103221] " rguenth at gcc dot gnu.org
2021-11-23 20:20 ` amacleod at redhat dot com
2021-11-25 15:21 ` amacleod at redhat dot com
2021-12-25  9:59 ` pinskia at gcc dot gnu.org
2022-01-12 20:45 ` amacleod at redhat dot com
2022-01-12 20:52 ` pinskia at gcc dot gnu.org
2022-01-12 20:59 ` amacleod at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).