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

            Bug ID: 126474
           Summary: wrong vec_cond+VIEW_CONVERT+negate -> .COND_NEG fold
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: aarch64-sve, wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64

#include <arm_sve.h>

__attribute__((noipa))
svint32_t f (svbool_t p, svfloat32_t a, svint32_t b)
{
  svfloat32_t n = -a;                   /* NEGATE_EXPR <svfloat32_t>  */
  return svsel_s32 (p, svreinterpret_s32_f32 (n), b);
}

int main (void)
{
  float av[64];
  int bv[64], rv[64];
  for (int i = 0; i < 64; i++) { av[i] = 1.0f; bv[i] = 77; rv[i] = 0; }
  svbool_t p = svwhilelt_b32 (0, 1);    /* lane 0 active only  */
  svfloat32_t a = svld1_f32 (svptrue_b32 (), av);
  svint32_t b = svld1_s32 (svptrue_b32 (), bv);
  svint32_t r = f (p, a, b);
  svst1_s32 (svptrue_b32 (), rv, r);
  __builtin_printf ("%d %d\n", rv[0], rv[1]);
  /* -1.0f has the bit pattern 0xbf800000 == -1082130432.  */
  if (rv[0] != (int) 0xbf800000 || rv[1] != 77)
    __builtin_abort ();
  return 0;
}

aborts for -O2 -march=armv8-a+sve but passes at -O0.
vec_cond+VIEW_CONVERT+negate -> .COND_NEG builds the IFN in the VEC_COND_EXPR
type instead of the negate type, turning a float negate into an integer negate

Reply via email to