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

            Bug ID: 97137
           Summary: Missed add-with-carry after FP compare
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

Extracted from 508.namd_r

void foo (double *r2i, double r2_0, double cutoff2_delta, int jout)
{
  bool test0 = (r2_0 < cutoff2_delta);
  jout += test0;
  r2i[jout] = r2_0;
}

produces

        xorl    %eax, %eax
        comisd  %xmm0, %xmm1
        seta    %al
        addl    %esi, %eax
        movsd   %xmm0, (%rdi,%rax,8)

while llvm optimizes this to

        ucomisd %xmm1, %xmm0
        adcl    $0, %esi
        movslq  %esi, %rax
        movsd   %xmm0, (%rdi,%rax,8)

possibly saving one register.  Note that clang needs -ffinite-math-only for
this.
I'm not sure how r2_0 < cutoff2_delta behaves with NaNs, but with
-ffinite-math-only we'd be sure there are none and thus even comisd set
of CF should be enough to optimize this.

Reply via email to