public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1591] loongarch: fix mulsidi3_64bit instruction
Date: Sun, 10 Jul 2022 03:34:16 +0000 (GMT)	[thread overview]
Message-ID: <20220710033416.8D5B5385C331@sourceware.org> (raw)

https://gcc.gnu.org/g:1fa42d62140b56589771eb3d46f89c810bfc8e0a

commit r13-1591-g1fa42d62140b56589771eb3d46f89c810bfc8e0a
Author: Xi Ruoyao <xry111@xry111.site>
Date:   Fri Jul 8 21:09:25 2022 +0800

    loongarch: fix mulsidi3_64bit instruction
    
    (mult (sign_extend:DI rj:SI) (sign_extend:DI rk:SI)) should be
    "mulw.d.w", not "mul.d".
    
    gcc/ChangeLog:
    
            * config/loongarch/loongarch.md (mulsidi3_64bit): Use mulw.d.w
            instead of mul.d.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/loongarch/mulw_d_w.c: New test.
            * gcc.c-torture/execute/mul-sext.c: New test.

Diff:
---
 gcc/config/loongarch/loongarch.md              |  2 +-
 gcc/testsuite/gcc.c-torture/execute/mul-sext.c | 20 ++++++++++++++++++++
 gcc/testsuite/gcc.target/loongarch/mulw_d_w.c  | 10 ++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index d3c809e25f3..8f8412fba84 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -621,7 +621,7 @@
 	(mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r"))
 		 (sign_extend:DI (match_operand:SI 2 "register_operand" "r"))))]
   "TARGET_64BIT"
-  "mul.d\t%0,%1,%2"
+  "mulw.d.w\t%0,%1,%2"
   [(set_attr "type" "imul")
    (set_attr "mode" "DI")])
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/mul-sext.c b/gcc/testsuite/gcc.c-torture/execute/mul-sext.c
new file mode 100644
index 00000000000..8b6800804fb
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/mul-sext.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+
+typedef __INT64_TYPE__ int64_t;
+typedef __INT32_TYPE__ int32_t;
+
+/* f() was misoptimized to a single "mul.d" instruction on LA64.  */
+__attribute__((noipa, noinline)) int64_t
+f(int64_t a, int64_t b)
+{
+  return (int64_t)(int32_t)a * (int64_t)(int32_t)b;
+}
+
+int
+main()
+{
+  int64_t a = 0x1145140000000001;
+  int64_t b = 0x1919810000000001;
+  if (f(a, b) != 1)
+    __builtin_abort();
+}
diff --git a/gcc/testsuite/gcc.target/loongarch/mulw_d_w.c b/gcc/testsuite/gcc.target/loongarch/mulw_d_w.c
new file mode 100644
index 00000000000..4ab7df8836b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/mulw_d_w.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mabi=lp64d" } */
+/* { dg-final { scan-assembler "mulw.d.w" } } */
+
+/* This should be optimized to mulw.d.w for LA64.  */
+__attribute__((noipa, noinline)) long
+f(long a, long b)
+{
+  return (long)(int)a * (long)(int)b;
+}


                 reply	other threads:[~2022-07-10  3:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220710033416.8D5B5385C331@sourceware.org \
    --to=xry111@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).