public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "klepikov.alex+bugs at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/54089] [SH] Refactor shift patterns
Date: Thu, 01 Jun 2023 11:18:00 +0000	[thread overview]
Message-ID: <bug-54089-4-9hgHNxoLd9@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-54089-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #50 from Alexander Klepikov <klepikov.alex+bugs at gmail dot com> ---
> > I've found that my patch catches integer division. In short, it appears to
> > work unpredictable. It looks like there's no easy way to catch right shift.
> 
> What do you mean it catches integer division? There could be several places
> during compilation, where the compiler will try to convert integer division
> to right shifts.  But it will not do so unless it's wrong.  The patterns you
> have added shouldn't match a division operation.

Ooh, my bad! You are absolutely right. A function is inlined and division is
converted to 4 'shar's which at combine pass are catched by 'define_insn
"ashrsi3_libcall_collapsed"' which is little unexpected to me. Of course, it is
expanded at 'split' pass to lib call. 5 and less right shifts should not
convert to a lib call, but that can be easily corrected.

But maybe there is a way to exclude particular insn from combine pass? (I guess
not).

Here are the files that confused me:

$ cat pr49880-3.c
/* Check that the option -mdiv=call-table works.  */
/* { dg-do link }  */
/* { dg-options "-mdiv=call-table" }  */

int
test00 (int a, int b)
{
  return a / b;
}

unsigned int
test01 (unsigned int a, unsigned b)
{
  return a / b;
}

int
main (int argc, char** argv)
{
  return test00 (argc, 123) + test01 (argc, 123);
}

Not-patched GCC

$ cat pr49880-3.s.clean
        .file   "pr49880-3.c"
        .text
        .text
        .align 1
        .align 2
        .global _test00
        .type   _test00, @function
_test00:
        mov.l   .L4,r0
        sts.l   pr,@-r15
        jsr     @r0
        nop
        lds.l   @r15+,pr
        rts
        nop
.L5:
        .align 2
.L4:
        .long   ___sdivsi3
        .size   _test00, .-_test00
        .align 1
        .align 2
        .global _test01
        .type   _test01, @function
_test01:
        mov.l   .L8,r0
        sts.l   pr,@-r15
        jsr     @r0
        nop
        lds.l   @r15+,pr
        rts
        nop
.L9:
        .align 2
.L8:
        .long   ___udivsi3
        .size   _test01, .-_test01
        .section        .text.startup,"ax",@progbits
        .align 1
        .align 2
        .global _main
        .type   _main, @function
_main:
        mov.l   .L11,r1
        dmuls.l r1,r4
        sts     mach,r0
        shar    r0
        shar    r0
        shar    r0
        shar    r0
        mov     r4,r1
        shll    r1
        subc    r1,r1
        sub     r1,r0
        mov.l   .L12,r1
        dmulu.l r1,r4
        sts     mach,r1
        sub     r1,r4
        shlr    r4
        add     r4,r1
        shlr2   r1
        shlr2   r1
        shlr2   r1
        rts
        add     r1,r0
.L13:
        .align 2
.L11:
        .long   558694933
.L12:
        .long   174592167
        .size   _main, .-_main
        .ident  "GCC: (GNU) 13.1.0"

Patched GCC

$ cat pr49880-3.s
        .file   "pr49880-3.c"
        .text
        .text
        .align 1
        .align 2
        .global _test00
        .type   _test00, @function
_test00:
        mov.l   .L4,r0
        sts.l   pr,@-r15
        jsr     @r0
        nop
        lds.l   @r15+,pr
        rts
        nop
.L5:
        .align 2
.L4:
        .long   ___sdivsi3
        .size   _test00, .-_test00
        .align 1
        .align 2
        .global _test01
        .type   _test01, @function
_test01:
        mov.l   .L8,r0
        sts.l   pr,@-r15
        jsr     @r0
        nop
        lds.l   @r15+,pr
        rts
        nop
.L9:
        .align 2
.L8:
        .long   ___udivsi3
        .size   _test01, .-_test01
        .section        .text.startup,"ax",@progbits
        .align 1
        .align 2
        .global _main
        .type   _main, @function
_main:
        mov.l   .L12,r2
        mov     r4,r1
        sts.l   pr,@-r15
        dmuls.l r2,r4
        mov.l   .L13,r2
        jsr     @r2
        sts     mach,r4
        mov     r1,r2
        shll    r2
        subc    r2,r2
        mov     r4,r0
        sub     r2,r0
        mov.l   .L14,r2
        dmulu.l r2,r1
        sts     mach,r2
        sub     r2,r1
        shlr    r1
        add     r1,r2
        shlr2   r2
        shlr2   r2
        shlr2   r2
        add     r2,r0
        lds.l   @r15+,pr
        rts
        nop
.L15:
        .align 2
.L12:
        .long   558694933
.L13:
        .long   ___ashiftrt_r4_4
.L14:
        .long   174592167
        .size   _main, .-_main
        .ident  "GCC: (GNU) 13.1.0"



Now concerning GCC testsuite. I ran it in such way:

make check RUNTESTFLAGS="CFLAGS='$CFLAGS -I/usr/local/sh-elf/include/'
--target_board=sh-sim\{-m2e,-m4\}\{-ml,-mb\}"

There are lots of failed tests on non-patched GCC. Even if I narrow tests list
to sh.exp, it still fails a lot of times. At last there's nothing in logs that
produce ICE in RTL. I'm not sure I could find a crash due to the patch at all,
even if it were there.

And finally, 'parallel' appears to be unnecessary, thank you for pointing.

  parent reply	other threads:[~2023-06-01 11:18 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-24 23:42 [Bug target/54089] New: " olegendo at gcc dot gnu.org
2012-07-24 23:46 ` [Bug target/54089] " olegendo at gcc dot gnu.org
2012-07-25 23:03 ` olegendo at gcc dot gnu.org
2012-07-27 17:36 ` olegendo at gcc dot gnu.org
2012-07-30  6:43 ` olegendo at gcc dot gnu.org
2012-08-09 21:55 ` olegendo at gcc dot gnu.org
2012-08-09 23:18 ` olegendo at gcc dot gnu.org
2012-08-09 23:28 ` olegendo at gcc dot gnu.org
2012-08-09 23:36 ` olegendo at gcc dot gnu.org
2012-08-09 23:43 ` olegendo at gcc dot gnu.org
2012-08-10  0:40 ` kkojima at gcc dot gnu.org
2012-08-10 14:25 ` rmansfield at qnx dot com
2012-08-10 15:40 ` olegendo at gcc dot gnu.org
2012-08-11 20:26 ` olegendo at gcc dot gnu.org
2012-08-16 23:13 ` olegendo at gcc dot gnu.org
2012-08-20 21:29 ` olegendo at gcc dot gnu.org
2012-08-22 22:52 ` olegendo at gcc dot gnu.org
2012-09-10 20:35 ` olegendo at gcc dot gnu.org
2012-09-10 21:27 ` olegendo at gcc dot gnu.org
2012-09-17 23:30 ` olegendo at gcc dot gnu.org
2012-09-19 17:49 ` olegendo at gcc dot gnu.org
2012-09-25 19:07 ` olegendo at gcc dot gnu.org
2012-09-30 18:46 ` olegendo at gcc dot gnu.org
2012-10-16 10:53 ` amylaar at gcc dot gnu.org
2012-10-16 11:49 ` olegendo at gcc dot gnu.org
2012-11-06 11:56 ` olegendo at gcc dot gnu.org
2012-11-07 23:32 ` olegendo at gcc dot gnu.org
2012-11-09 10:48 ` olegendo at gcc dot gnu.org
2012-11-09 13:29 ` amylaar at gcc dot gnu.org
2012-11-13  1:14 ` olegendo at gcc dot gnu.org
2013-02-16 11:36 ` olegendo at gcc dot gnu.org
2013-12-17 11:11 ` olegendo at gcc dot gnu.org
2014-05-16 23:12 ` olegendo at gcc dot gnu.org
2014-12-16 21:38 ` olegendo at gcc dot gnu.org
2015-05-30 13:51 ` bugdal at aerifal dot cx
2015-05-30 14:11 ` olegendo at gcc dot gnu.org
2015-05-30 14:35 ` bugdal at aerifal dot cx
2015-05-30 14:42 ` olegendo at gcc dot gnu.org
2015-05-30 14:46 ` bugdal at aerifal dot cx
2015-05-30 14:57 ` olegendo at gcc dot gnu.org
2015-08-11  3:56 ` bugdal at aerifal dot cx
2015-08-11 14:17 ` olegendo at gcc dot gnu.org
2015-08-11 21:05 ` segher at gcc dot gnu.org
2015-08-12  1:30 ` segher at gcc dot gnu.org
2023-06-01  7:32 ` klepikov.alex+bugs at gmail dot com
2023-06-01  8:21 ` olegendo at gcc dot gnu.org
2023-06-01 11:18 ` klepikov.alex+bugs at gmail dot com [this message]
2023-06-01 12:08 ` olegendo at gcc dot gnu.org
2023-06-01 17:45 ` segher at gcc dot gnu.org
2023-06-01 20:46 ` olegendo at gcc dot gnu.org
2023-06-03  7:24 ` klepikov.alex+bugs at gmail dot com
2023-06-03  8:50 ` olegendo at gcc dot gnu.org
2023-06-03 15:43 ` klepikov.alex+bugs at gmail dot com
2023-06-03 16:09 ` olegendo at gcc dot gnu.org
2023-06-04 18:35 ` klepikov.alex+bugs at gmail dot com
2023-06-05  0:03 ` olegendo at gcc dot gnu.org
2023-06-06 10:30 ` klepikov.alex+bugs at gmail dot com
2023-06-06 10:51 ` olegendo at gcc dot gnu.org
2023-06-06 12:17 ` klepikov.alex+bugs at gmail dot com
2023-06-06 12:39 ` olegendo at gcc dot gnu.org
2023-06-06 12:55 ` klepikov.alex+bugs at gmail dot com
2023-06-06 16:10 ` klepikov.alex+bugs at gmail dot com
2023-06-06 19:07 ` klepikov.alex+bugs at gmail dot com
2023-06-06 23:11 ` olegendo at gcc dot gnu.org
2023-06-08 12:07 ` klepikov.alex+bugs at gmail dot com
2023-06-08 12:09 ` klepikov.alex+bugs at gmail dot com
2023-06-08 13:22 ` olegendo at gcc dot gnu.org
2023-06-08 15:22 ` klepikov.alex+bugs at gmail dot com
2023-06-08 20:17 ` olegendo at gcc dot gnu.org
2023-06-14  9:30 ` klepikov.alex+bugs at gmail dot com
2023-06-14  9:31 ` klepikov.alex+bugs at gmail dot com
2023-06-16 13:57 ` klepikov.alex+bugs at gmail dot com
2023-06-16 21:58 ` olegendo at gcc dot gnu.org
2023-06-17  6:08 ` klepikov.alex+bugs at gmail dot com
2023-06-17  7:06 ` olegendo at gcc dot gnu.org
2023-06-17  8:24 ` klepikov.alex+bugs at gmail dot com
2023-06-17  9:46 ` olegendo at gcc dot gnu.org
2023-06-17 11:00 ` klepikov.alex+bugs at gmail dot com
2023-06-17 17:57 ` klepikov.alex+bugs at gmail dot com
2023-06-20 11:28 ` klepikov.alex+bugs at gmail dot com
2023-06-20 17:03 ` klepikov.alex+bugs at gmail dot com
2023-06-20 23:46 ` olegendo at gcc dot gnu.org
2023-06-21 11:51 ` klepikov.alex+bugs at gmail dot com
2023-06-21 20:13 ` segher at gcc dot gnu.org
2023-06-21 20:32 ` segher at gcc dot gnu.org
2023-06-22 11:09 ` klepikov.alex+bugs at gmail dot com
2023-06-22 11:44 ` olegendo at gcc dot gnu.org
2023-06-22 12:34 ` klepikov.alex+bugs at gmail dot com
2023-06-23  6:02 ` klepikov.alex+bugs at gmail dot com
2023-06-23  6:06 ` olegendo at gcc dot gnu.org
2023-06-23 14:11 ` segher at gcc dot gnu.org
2023-07-06 14:16 ` olegendo at gcc dot gnu.org
2023-07-07 11:10 ` klepikov.alex+bugs at gmail dot com
2023-07-07 11:45 ` olegendo at gcc dot gnu.org
2023-07-08  7:56 ` klepikov.alex+bugs at gmail dot com
2023-07-09 13:55 ` olegendo at gcc dot gnu.org
2023-07-10 14:02 ` klepikov.alex+bugs at gmail dot com
2023-07-13 23:40 ` olegendo at gcc dot gnu.org
2023-07-14 14:31 ` klepikov.alex+bugs at gmail dot com
2023-10-13  5:02 ` olegendo at gcc dot gnu.org
2023-10-14 15:20 ` klepikov.alex+bugs at gmail dot com
2023-10-15  1:06 ` olegendo at gcc dot gnu.org

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-54089-4-9hgHNxoLd9@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).