public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vineetg at rivosinc dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/108987] New: [13 Regression] RISC-V: shiftadd cost model bug needlessly preferring syth_multiply
Date: Wed, 01 Mar 2023 19:34:20 +0000	[thread overview]
Message-ID: <bug-108987-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108987

            Bug ID: 108987
           Summary: [13 Regression] RISC-V: shiftadd cost model bug
                    needlessly preferring syth_multiply
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vineetg at rivosinc dot com
  Target Milestone: ---

gcc trunk is preferring synthetic multiply using shift+add even when they are
costlier than multiply.

unsigned long long f5(unsigned long long i)
{
  return i * 0x0202020202020202ULL;
}

riscv64-unknown-linux-gnu-gcc -c -O2 -march=rv64gc_zba

f5:
        slli    a5,a0,8
        add     a0,a5,a0
        slli    a5,a0,16
        add     a0,a0,a5
        slli    a5,a0,32
        add     a0,a0,a5
        slli    a0,a0,1
        ret

With gcc 12.2 this used to be

f5:
        lui     a5,%hi(.LC0)
        ld      a5,%lo(.LC0)(a5)
        mul     a0,a0,a5
        ret

This is a regression introduced by commit f90cb39235c4 ("RISC-V: costs: support
shift-and-add in strength-reduction"). It introduced the cost for
shift[1-3]+add (to favor SH*ADD) but due to a coding bug ended up doing this
for all shift values, affecting synth multiply among others.

This showed up as dynamic icount regression in SPEC 531.deepsjeng.

             reply	other threads:[~2023-03-01 19:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-01 19:34 vineetg at rivosinc dot com [this message]
2023-03-01 19:56 ` [Bug target/108987] " vineetg at rivosinc dot com
2023-03-02 10:11 ` rguenth at gcc dot gnu.org
2023-03-06 21:50 ` vineetg at rivosinc dot com

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=bug-108987-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).