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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot 
gnu.org

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So looking into the code.
In forwprop2 we have:
  iftmp.1_3 = (unsigned int) _13;
  b.4_2 = b;
  _10 = MAX_EXPR <b.4_2, f_7(D)>;
  if (_10 != 0)
    goto <bb 5>; [50.00%]
  else
    goto <bb 6>; [50.00%]

  <bb 5> [local count: 536870912]:

  <bb 6> [local count: 1073741824]:
  # _14 = PHI <f_7(D)(5), 0(4)>
  iftmp.3_4 = (unsigned int) _14;
  if (iftmp.1_3 != iftmp.3_4)

Why didn't forwprop change `iftmp.1_3 != iftmp.3_4` into `_13 != _14`.

The other thing is:
  _10 = MAX_EXPR <b.4_2, f_7(D)>;
  if (_10 != 0)

Since this is unsigned, here `max<a,b> != 0` could be `a != 0 | b != 0` which
then will optmize this.


So that is the following:
```
template<class T>
T max(T a, T b)
{
        return a > b ? a : b;
}

int f1(unsigned f, unsigned t)
{
  return max(f, t) != 0;
}
```

Should be optimized to `(f | t) != 0`.

I will handle this. Min is similar but clang does not optimize that.

Reply via email to