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

            Bug ID: 112361
           Summary: [14 Regression] avx512f-reduce-op-1.c miscompiled
                    since r14-5076
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

Since r14-5076-g01c18f58d37865d5f3bbe93e666183b54ec608c7 I see
gcc.target/i386/avx512f-reduce-op-1.c execution failure.
Reduced -O2 -mavx512f:
__attribute__((noipa)) float
foo (void)
{
  float a[16] = { 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4 };
  float r3 = 0.0f;
  for (int i = 0; i < 16; i++)
    if ((1 << i) & 0xA6BA)
      r3 = r3 + a[i];
  return r3;
}

int
main ()
{
  if (foo () != 37.0f)
    __builtin_abort ();
}
where before r14-5076 r3 has been correctly computed as 37.0f, but starting
with r14-5076 it is 64.0f, i.e. the masking is ignored and all elements are
added, not just the ones under the mask.
The ifcvt dump has
  _1 = 42682 >> i_31;
  _2 = _1 & 1;
  _24 = _2 != 0;
  _3 = a[i_31];
  _ifc__43 = .COND_ADD (_24, r3_29, _3, r3_29);
which I assume is correct, and vect dump shows computation of the mask but then
instead of using masked addition and at the end of loop reduction (well, can we
vectorize it at all without -ffast-math?) it scalarizes the addition but
doesn't actually conditionalize it.  Note, with -O2 -mavx512f -ffast-math the
.COND_ADD is actually vectorized and so correctly returns 37.0f.

Reply via email to