diff --git a/gcc/config/loongarch/simd.md b/gcc/config/loongarch/simd.md index 93fb39abcf5b..8ac1d75a85cb 100644 --- a/gcc/config/loongarch/simd.md +++ b/gcc/config/loongarch/simd.md @@ -426,6 +426,37 @@ [(set_attr "type" "simd_fcmp") (set_attr "mode" "")]) +; [x]vf{min/max} instructions are IEEE-754-2008 conforming, use them for +; the corresponding IEEE-754-2008 operations. We must use UNSPEC instead +; of smin/smax though, see PR105414 and PR107013. + +(define_int_iterator UNSPEC_FMAXMIN [UNSPEC_FMAX UNSPEC_FMIN]) +(define_int_attr fmaxmin [(UNSPEC_FMAX "fmax") (UNSPEC_FMIN "fmin")]) + +(define_insn "3" + [(set (match_operand:FVEC 0 "register_operand" "=f") + (unspec:FVEC [(match_operand:FVEC 1 "register_operand" "f") + (match_operand:FVEC 2 "register_operand" "f")] + UNSPEC_FMAXMIN))] + "" + "v.\t%0,%1,%2" + [(set_attr "type" "simd_fminmax") + (set_attr "mode" "")]) + +;; ... and also reduc operations. +(define_expand "reduc__scal_" + [(match_operand: 0 "register_operand") + (match_operand:FVEC 1 "register_operand") + (const_int UNSPEC_FMAXMIN)] + "" +{ + rtx tmp = gen_reg_rtx (mode); + loongarch_expand_vector_reduc (gen_3, tmp, operands[1]); + emit_insn (gen_vec_extract (operands[0], tmp, + const0_rtx)); + DONE; +}) + ; The LoongArch SX Instructions. (include "lsx.md") diff --git a/gcc/testsuite/gcc.target/loongarch/vfmax-vfmin.c b/gcc/testsuite/gcc.target/loongarch/vfmax-vfmin.c new file mode 100644 index 000000000000..811fee361c33 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/vfmax-vfmin.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mtune=la464 -mlasx" } */ +/* { dg-final { scan-assembler "\tvfmin\\.d" } } */ +/* { dg-final { scan-assembler "\tvfmax\\.d" } } */ +/* { dg-final { scan-assembler "\txvfmin\\.d" } } */ +/* { dg-final { scan-assembler "\txvfmax\\.d" } } */ +/* { dg-final { scan-assembler "\tvfmin\\.s" } } */ +/* { dg-final { scan-assembler "\tvfmax\\.s" } } */ +/* { dg-final { scan-assembler "\txvfmin\\.s" } } */ +/* { dg-final { scan-assembler "\txvfmax\\.s" } } */ + +#define T(OP) __typeof__ (__builtin_##OP (0, 0)) + +#define TEST(OP, LEN) \ +void \ +test_##OP##LEN (T (OP) *restrict dest, \ + const T (OP) *restrict src1, \ + const T (OP) *restrict src2) \ +{ \ + for (int i = 0; i < LEN / sizeof (T(OP)); i++) \ + dest[i] = __builtin_##OP (src1[i], src2[i]); \ +} + +TEST(fmin, 16) +TEST(fmax, 16) +TEST(fmin, 32) +TEST(fmax, 32) +TEST(fminf, 16) +TEST(fmaxf, 16) +TEST(fminf, 32) +TEST(fmaxf, 32)