gcc/

        * config/loongarch/loongarch.md (fixuns_truncsfsi2): Use LSX if
        available.
        (fixuns_truncsfdi2): Likewise.
        (fixuns_truncdfsi2): Likewise.
        (fixuns_truncdfdi2): Likewise.

gcc/testsuite/

        * gcc.target/loongarch/fixuns-lsx.c: New test.
---
 gcc/config/loongarch/loongarch.md             | 39 +++++++++++++++++++
 .../gcc.target/loongarch/fixuns-lsx.c         | 27 +++++++++++++
 2 files changed, 66 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/fixuns-lsx.c

diff --git a/gcc/config/loongarch/loongarch.md 
b/gcc/config/loongarch/loongarch.md
index 8eef348af29..c54fb578a1e 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -2109,6 +2109,17 @@ (define_expand "fixuns_truncdfsi2"
    (match_operand:DF 1 "register_operand")]
   "TARGET_DOUBLE_FLOAT"
 {
+  if (ISA_HAS_LSX)
+    {
+      rtx tmp = gen_reg_rtx (V2DImode);
+      operands[1] = loongarch_adjust_scalar_input_for_simd (operands[1],
+                                                           V2DFmode);
+      emit_insn (gen_lsx_vftintrz_lu_d (tmp, operands[1]));
+      tmp = gen_lowpart (V4SImode, tmp);
+      emit_insn (gen_lsx_vpickve2gr_w (operands[0], tmp, const0_rtx));
+      DONE;
+    }
+
   rtx reg1 = gen_reg_rtx (DFmode);
   rtx reg2 = gen_reg_rtx (DFmode);
   rtx reg3 = gen_reg_rtx (SImode);
@@ -2152,6 +2163,16 @@ (define_expand "fixuns_truncdfdi2"
    (match_operand:DF 1 "register_operand")]
   "TARGET_64BIT && TARGET_DOUBLE_FLOAT"
 {
+  if (ISA_HAS_LSX)
+    {
+      rtx tmp = gen_reg_rtx (V2DImode);
+      operands[1] = loongarch_adjust_scalar_input_for_simd (operands[1],
+                                                           V2DFmode);
+      emit_insn (gen_lsx_vftintrz_lu_d (tmp, operands[1]));
+      emit_insn (gen_lsx_vpickve2gr_d (operands[0], tmp, const0_rtx));
+      DONE;
+    }
+
   rtx reg1 = gen_reg_rtx (DFmode);
   rtx reg2 = gen_reg_rtx (DFmode);
   rtx reg3 = gen_reg_rtx (DImode);
@@ -2193,6 +2214,16 @@ (define_expand "fixuns_truncsfsi2"
    (match_operand:SF 1 "register_operand")]
   "TARGET_HARD_FLOAT"
 {
+  if (ISA_HAS_LSX)
+    {
+      rtx tmp = gen_reg_rtx (V4SImode);
+      operands[1] = loongarch_adjust_scalar_input_for_simd (operands[1],
+                                                           V4SFmode);
+      emit_insn (gen_lsx_vftintrz_wu_s (tmp, operands[1]));
+      emit_insn (gen_lsx_vpickve2gr_w (operands[0], tmp, const0_rtx));
+      DONE;
+    }
+
   rtx reg1 = gen_reg_rtx (SFmode);
   rtx reg2 = gen_reg_rtx (SFmode);
   rtx reg3 = gen_reg_rtx (SImode);
@@ -2234,6 +2265,14 @@ (define_expand "fixuns_truncsfdi2"
    (match_operand:SF 1 "register_operand")]
   "TARGET_64BIT && TARGET_DOUBLE_FLOAT"
 {
+  if (ISA_HAS_LSX)
+    {
+      rtx tmp = gen_reg_rtx (DFmode);
+      emit_insn (gen_extendsfdf2 (tmp, operands[1]));
+      emit_insn (gen_fixuns_truncdfdi2 (operands[0], tmp));
+      DONE;
+    }
+
   rtx reg1 = gen_reg_rtx (SFmode);
   rtx reg2 = gen_reg_rtx (SFmode);
   rtx reg3 = gen_reg_rtx (DImode);
diff --git a/gcc/testsuite/gcc.target/loongarch/fixuns-lsx.c 
b/gcc/testsuite/gcc.target/loongarch/fixuns-lsx.c
new file mode 100644
index 00000000000..da9b7d8379e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/fixuns-lsx.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=loongarch64 -mabi=lp64d -mlsx" } */
+/* { dg-final { scan-assembler-times "vftintrz.\[wl\]u" 4 } } */
+
+unsigned int
+t1 (float x)
+{
+  return x;
+}
+
+unsigned int
+t2 (double x)
+{
+  return x;
+}
+
+unsigned long
+t3 (float x)
+{
+  return x;
+}
+
+unsigned long
+t4 (double x)
+{
+  return x;
+}
-- 
2.56.1

Reply via email to