public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Liao Shihua <shihua@iscas.ac.cn>
To: gcc-patches@gcc.gnu.org
Cc: kito.cheng@gmail.com, jeffreyalaw@gmail.com, jiawei@iscas.ac.cn,
	Liao Shihua <shihua@iscas.ac.cn>
Subject: [PATCH] RISC-V: Fix missing boolean_expression in zmmul extension
Date: Thu, 23 May 2024 18:45:21 +0800	[thread overview]
Message-ID: <20240523104521.328214-1-shihua@iscas.ac.cn> (raw)

Missing boolean_expression TARGET_ZMMUL in riscv_rtx_costs() casuse different instructions when multiplying an integer with a constant.
( https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1482 )

int foo(int *ib) {
    *ib = *ib * 33938;
    return 0;
}

rv64im:
        lw      a4,0(a1)
        li      a5,32768
        addiw   a5,a5,1170
        mulw    a5,a5,a4
        sw      a5,0(a1)
        ret

rv64i_zmmul:
        lw      a4,0(a1)
        slliw   a5,a4,5
        addw    a5,a5,a4
        slliw   a5,a5,3
        addw    a5,a5,a4
        slliw   a5,a5,3
        addw    a5,a5,a4
        slliw   a5,a5,3
        addw    a5,a5,a4
        slliw   a5,a5,1
        sw      a5,0(a1)
        ret

Fixed.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_rtx_costs): Add TARGET_ZMMUL.

---
 gcc/config/riscv/riscv.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 85df5b7ab49..580ae007181 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -3753,7 +3753,7 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
     case MULT:
       if (float_mode_p)
 	*total = tune_param->fp_mul[mode == DFmode];
-      else if (!TARGET_MUL)
+      else if (!(TARGET_MUL || TARGET_ZMMUL))
 	/* Estimate the cost of a library call.  */
 	*total = COSTS_N_INSNS (speed ? 32 : 6);
       else if (GET_MODE_SIZE (mode).to_constant () > UNITS_PER_WORD)
-- 
2.34.1


             reply	other threads:[~2024-05-23 10:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-23 10:45 Liao Shihua [this message]
2024-05-23 13:12 ` Kito Cheng

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=20240523104521.328214-1-shihua@iscas.ac.cn \
    --to=shihua@iscas.ac.cn \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=jiawei@iscas.ac.cn \
    --cc=kito.cheng@gmail.com \
    /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).