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

            Bug ID: 110089
           Summary: sub-optimal code for attempting to produce JNA (jump
                    on CF or ZF)
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

void bar ();
void foo (unsigned int n, unsigned s)
{
  do
    {
      bar (MIN (n, s));
    }
  while (!__builtin_usub_overflow (n, s, &n) && n != 0);
}

tries to construct a loop processing N elements S at a time and in the
last iteration N' < S elements.  The x86 sub instruction sets CF and ZF
so a jump on CF or ZF aka JNA (aka ! GT) should be possible but I can't
arrive at that code gen.

We expand from

  # n_4 = PHI <n_6(D)(2), _2(3)>
  _1 = n_4 % s_8(D);
  bar (_1);
  _10 = .SUB_OVERFLOW (n_4, s_8(D));
  _2 = REALPART_EXPR <_10>;
  _3 = IMAGPART_EXPR <_10>;
  _11 = _2 != 0;
  _15 = _3 ^ 1;
  _12 = (_Bool) _15;
  _13 = _11 & _12;
  if (_13 != 0)
    goto <bb 3>; [89.30%]

but that's all too complicated for combine or compare-elim

Reply via email to