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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.5
   Last reconfirmed|                            |2024-03-08
            Summary|Missed optimization:        |[11/12/13/14 Regression]
                   |x*(x||b) => x               |Missed optimization:
                   |                            |x*(x||b) => x
      Known to fail|                            |8.1.0
      Known to work|                            |7.5.0
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
In GCC 7, before PRE we had:
```
  # iftmp.0_3 = PHI <_8(3), 1(5)>
  _2 = iftmp.0_3 * x_4(D);
```

Which was able to optimized by PRE to:
```
  _9 = x_4(D) * _8;

  <bb 4> [100.00%]:
  # iftmp.0_3 = PHI <_8(3), 1(2)>
  # prephitmp_10 = PHI <_9(3), x_4(D)(2)>
  a = prephitmp_10;
```

Which is how GCC 7 was able to optimize it.

In GCC8+, reassociatation takes:
```
  <bb 2> [local count: 1073741825]:
  if (x_4(D) != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 3>; [50.00%]

  <bb 3> [local count: 536870912]:
  b.1_1 = b;
  _7 = b.1_1 != 0;
  _8 = (int) _7;

  <bb 4> [local count: 1073741825]:
  # iftmp.0_3 = PHI <_8(3), 1(2)>
  _2 = iftmp.0_3 * x_4(D);
```

Into:
```
  _9 = x_4(D) | b.1_1;
  _10 = _9 != 0;
  _7 = b.1_1 != 0;
  _11 = (int) _10;
  _8 = (int) _7;
  _2 = x_4(D) * _11;
```

Which no longer can be optimized to just x_4(D).

Maybe:
(simplify
 (mult:c @0 (convert? (ne (bit_ior:c @0 @1) integer_zero_p)))
 @0)

Like similarly was done for  `a * !a` just recently. Note this won't catch all
cases though as @0 be deep in the bit_ior chain but it will catch some.

Reply via email to