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

            Bug ID: 117013
           Summary: aarch64 should define spaceship<mode>4 optab
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

Please look at code generation for
signed char f1 (float x, float y) { if (x == y) return 0; else if (x < y)
return -1; else if (x > y) return 1; else return 2; }
__attribute__((optimize ("fast-math"))) signed char f2 (float x, float y) { if
(x == y) return 0; else if (x < y) return -1; else if (x > y) return 1; else
return 2; }
signed char f3 (float x, float y) { if (x == y) return 0; else if (x < y)
return -1; else if (x > y) return 1; else return -127; }
void g1 (void); void g2 (void); void g3 (void); void g4 (void);
void f4 (float x, float y) { if (x == y) g1 (); else if (x < y) g2 (); else if
(x > y) g3 (); else g4 (); }
signed char f5 (int x, int y) { if (x == y) return 0; else if (x < y) return
-1; else return 1; }
signed char f6 (unsigned x, unsigned y) { if (x == y) return 0; else if (x < y)
return -1; else return 1; }
signed char f7 (int x, int y) { return (int) (x > y) - (int) (x < y); }
signed char f8 (unsigned x, unsigned y) { return (int) (x > y) - (int) (x < y);
}

The above is C version of various x <=> y C++ cases (and f7/f8 are one possible
way how to also emit what f5/f6 does differently).

This shows aarch64 suffers from similar issue why spaceship optab has been
introduced, at least the two comparisons
        fcmp    s0, s1
        mov     w0, 0
        beq     .L2
        fcmpe   s0, s1
        bmi     .L5
        cset    w0, gt
        mov     w1, 2
        sub     w0, w1, w0
.L2:
        ret
.L5:
        mov     w0, -1
        ret
look unnecessary and by defining at least spaceship{sf,df}4 one could do just
one comparison instead of two and just test the flags.
Whether it would be helpful to also define the patterns for integral modes is
something that needs to be carefully judged,
i.e. whether you get now for the comparisons into -1, 0, 1 values optimal code
or whether something different is needed.

Reply via email to