On Mon, Jan 31, 2022 at 2:13 AM Jakub Jelinek <ja...@redhat.com> wrote:
>
> On Sun, Jan 30, 2022 at 10:16:44AM +0000, Navid Rahimi via Gcc-patches wrote:
> > Thanks Jakob for the correction. Sadly, I didn’t have any access to any non 
> > x86 architecture. But x86 was fully tested and there was no regression.
> >
> > In my spare time I will look at implementation of this for short-circuit 
> > targets.
>
> Note, it isn't just about those targets.
> If you write the code as:
> _Bool
> g (_Bool a, _Bool b)
> {
>   _Bool c;
>   if (!a)
>     c = 0;
>   else if (!b)
>     c = 0;
>   else
>     c = 1;
>   return c == (a ^ b);
> }
> instead, it will not match either, not even on x86, even when it is
> equivalent.
>
> Though, maybe for non-short-circuiting targets we should recognize this
> somewhere and turn into c = a & b;
>
> Since phiopt2 it is:
>   <bb 2> [local count: 1073741824]:
>   if (a_4(D) != 0)
>     goto <bb 3>; [50.00%]
>   else
>     goto <bb 4>; [50.00%]
>
>   <bb 3> [local count: 536870913]:
>   _8 = (int) b_5(D);
>
>   <bb 4> [local count: 1073741824]:
>   # iftmp.0_3 = PHI <_8(3), 0(2)>
> and phiopt3 makes
>   <bb 2> [local count: 1073741824]:
>   if (a_4(D) != 0)
>     goto <bb 3>; [50.00%]
>   else
>     goto <bb 4>; [50.00%]
>
>   <bb 3> [local count: 536870913]:
>
>   <bb 4> [local count: 1073741824]:
>   # _9 = PHI <b_5(D)(3), 0(2)>
>   iftmp.0_3 = (int) _9;
> out of that.
>
> CCing Andrew if he'd like to have a look for GCC 13.

Yes I have a patch to recognize:
  if (a_3(D) != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 3>; [50.00%]

  <bb 3> [local count: 536870912]:

  <bb 4> [local count: 1073741824]:
  # c_2 = PHI <0(3), b_4(D)(2)>

already (a ? b : 0) into a & b.

This is already recorded as PR 89263.

Thanks,
Andrew Pinski

>
>         Jakub
>

Reply via email to