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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=55629

--- Comment #7 from Drea Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Drea Pinski from comment #5)
> https://gcc.gnu.org/pipermail/gcc-patches/2017-November/489192.html

So I now have a similar patch but in forwprop instead.
I use gimple_fold_stmt_to_constant_1 instead of the custom code in
fold_use_into_phi .

The valueize callback is simple as this:
```
static tree
phi_valueization (tree val)
{
  if (TREE_CODE (val) == SSA_NAME)
    {
      gphi *stmt = dyn_cast<gphi*> (SSA_NAME_DEF_STMT (val));
      if (stmt
          && gimple_bb (stmt) == phi_valueization_edge->dest)
        return gimple_phi_arg_def (stmt, phi_valueization_edge->dest_idx);
    }
  return val;
}
```
And then don't follow SSA names otherwise.

This allows us to use the information from the edge to form the value.

E.g.
_1 = PHI <1 (2), 0 (3)>
_2 = PHI <0 (2), 1 (3)>

_3 = _1 | _2;

Will be optimized to just:
```
_3 = PHI <1 (2), 1 (3)>
```

It also allows for PR 55629 to be fixed.

Reply via email to