public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/108987] New: [13 Regression] RISC-V: shiftadd cost model bug needlessly preferring syth_multiply
@ 2023-03-01 19:34 vineetg at rivosinc dot com
  2023-03-01 19:56 ` [Bug target/108987] " vineetg at rivosinc dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vineetg at rivosinc dot com @ 2023-03-01 19:34 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-06 21:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 19:34 [Bug target/108987] New: [13 Regression] RISC-V: shiftadd cost model bug needlessly preferring syth_multiply vineetg at rivosinc dot com
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

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).