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

            Bug ID: 118910
           Summary: Promote an expression equivalence to a name
                    equivalence in DOM
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: law at gcc dot gnu.org
  Target Milestone: ---

Created attachment 60517
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60517&action=edit
POC patch

In the context of bz81958 I speculated that improving the way we handle
conditional equivalences a bit could improve jump threading and ultimately
resolve the missed optimization leading to the false positive uninitialized
warning.

Since then we've moved away from DOM threading, so those ideas won't solve that
particular bz's problem.  But the ideas may still be found and provide value.

The purpose of this bz is to record the ideas independently and trigger an
evaluation of whether or not they are worth pushing beyond the initial proof of
concept code.

We have a structure which records equivalenes related to edges so that we can
add those equivalences to the various tables as we traverse edges.  There are
two forms of edge equivalences we track.

[01] = a COND b

Is used to record the equivalences created by the branch itself.  We can look
the RHS up in the expression table and it'll report back the LHS (a constant
indicating branch direction).

Second are simple a = b equivalences.

THe idea is that we can promote an expression equivalence to a simple
equivalence by propagating known const/copy values into the expression
equivalence and simplifying.

So if the edge had

1 = a GE b

If we know that a has the value zero we propagate that in resulting in

1 = 0 GE b

We then fold/simplify the RHS.  In the case I was looking at B is an unsigned
type.  So the net after simplificatoin is 1 = (0 EQ b) meaning we can record b
= 0 as we traverse the edge.

I'll attach a very rough POC that could probably be used for some initial
evaluation.  I have a suspicion this would be generally useful as I've seen it
identify caess for promotion.  What I haven't done is run a wide body of code
through it to see if it helps in practice (and to generate any tests).

Reply via email to