[Bug tree-optimization/95489] Failure to optimize x && (x & y) to x & y

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jun 3 06:39:46 GMT 2020


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-06-03
           Keywords|                            |easyhack
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
phiopt1 sees

  <bb 2> :
  if (x_3(D) != 0)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  _1 = x_3(D) & y_4(D);
  if (_1 != 0)
    goto <bb 5>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 4> :

  <bb 5> :
  # iftmp.0_2 = PHI <1(3), 0(4)>
  return iftmp.0_2;

and ifcombine_ifandif fails to combine the conditions via
maybe_fold_and_comparisons.  Via ifcombine we're looking also
at simplifying

  _tem1 = _1 != 0;
  _tem2 = x_3(D) != 0;
  _tem1 & _tem2

and thus

  (bit_and (ne (bit_and x_3 y_4) 0) (ne x_3 0))

where I'd say we miss

  (bit_and (ne @0 integer_zerop) (ne @1 integer_zerop))

->

  (ne (bit_and @0 @1) integer_zerop)

if @0 and @1 have compatible enough types.  That would probably do the
trick here.  Eventually works for generic equal values besides zero.
And also for bit_ior (but there only for special constants).


More information about the Gcc-bugs mailing list