https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117015
Bug ID: 117015 Summary: s390 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 s390x suffers from similar issue why spaceship optab has been introduced, at least the two comparisons cebr %f0,%f2 je .L4 kebr %f0,%f2 jl .L5 jnh .L8 lhi %r2,1 .L2: sllg %r0,%r2,56 srag %r2,%r0,56 br %r14 .L8: lhi %r2,2 sllg %r0,%r2,56 srag %r2,%r0,56 br %r14 .L4: lhi %r2,0 sllg %r0,%r2,56 srag %r2,%r0,56 br %r14 .L5: lhi %r2,255 j .L2 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. Ditto what code sequence is best for say f1/f2, currently it seems to be quite branchy and has 3 different sign extensions of constants. E.g. f8 doesn't have any branches but is quite long.