gcc/ChangeLog:

        * config/loongarch/loongarch.md (floatunssidf2): New expander.
        (floatunsdidf2): Ditto.

gcc/testsuite/ChangeLog:

        * gcc.target/loongarch/la64/unsigned-double.c: New test.
---
 gcc/config/loongarch/loongarch.md             | 26 +++++++++++++++++
 .../loongarch/la64/unsigned-double.c          | 28 +++++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/la64/unsigned-double.c

diff --git a/gcc/config/loongarch/loongarch.md 
b/gcc/config/loongarch/loongarch.md
index 92ca2348864..0dc6b7fa0d4 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -2101,6 +2101,32 @@ (define_insn "floatdisf2"
    (set_attr "mode" "SF")
    (set_attr "cnv_mode"        "I2S")])
 
+;; Convert unsigned integers (SI/DI) to double.
+
+(define_expand "floatunssidf2"
+  [(set (match_operand:DF 0 "register_operand")
+        (unsigned_float:DF (match_operand:SI 1 "register_operand")))]
+  "TARGET_64BIT && TARGET_DOUBLE_FLOAT"
+{
+  rtx tmp = gen_reg_rtx (DImode);
+  emit_insn (gen_zero_extendsidi2 (tmp, operands[1]));
+  emit_insn (gen_floatdidf2 (operands[0], tmp));
+  DONE;
+})
+
+(define_expand "floatunsdidf2"
+  [(set (match_operand:DF 0 "register_operand")
+    (unsigned_float:DF (match_operand:DI 1 "register_operand")))]
+  "ISA_HAS_LSX"
+{
+  rtx vec_op1 = gen_reg_rtx (V2DImode);
+  emit_insn (gen_lsx_vreplgr2vr_d (vec_op1, operands[1]));
+  rtx vec_op0 = gen_reg_rtx (V2DFmode);
+  emit_insn (gen_floatunsv2div2df2 (vec_op0, vec_op1));
+  emit_move_insn (operands[0], lowpart_subreg (DFmode, vec_op0, V2DFmode));
+  DONE;
+})
+
 ;; Convert a floating-point value to an unsigned integer.
 
 (define_expand "fixuns_truncdfsi2"
diff --git a/gcc/testsuite/gcc.target/loongarch/la64/unsigned-double.c 
b/gcc/testsuite/gcc.target/loongarch/la64/unsigned-double.c
new file mode 100644
index 00000000000..cf322b8a0a3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/la64/unsigned-double.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mlsx" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+/*
+** foo1:
+**     bstrpick\.d     \$r4,\$r4,31,0
+**     movgr2fr\.d     \$f0,\$r4
+**     ffint\.d\.l     \$f0,\$f0
+**     jr      \$r1
+*/
+double
+foo1 (unsigned int a)
+{
+  return (double)a;
+}
+
+/*
+** foo2:
+**     vreplgr2vr\.d   \$vr0,\$r4
+**     vffint\.d\.lu   \$vr0,\$vr0
+**     jr      \$r1
+*/
+double
+foo2 (unsigned long a)
+{
+  return (double)a;
+}
-- 
2.20.1

Reply via email to