public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "olegendo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/51244] [SH] Inefficient conditional branch and code around T bit Date: Thu, 05 Dec 2013 17:54:00 -0000 [thread overview] Message-ID: <bug-51244-4-V4pPHMVNFN@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-51244-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51244 --- Comment #72 from Oleg Endo <olegendo at gcc dot gnu.org> --- The original test case in PR 59343 is an interesting one with regard to T bit optimizations (or the lack thereof): void validate_number (char **numbertext) { char *ptr = *numbertext; int valid = (ptr != 0) && (*ptr); for ( ; valid && *ptr; ++ptr) valid = (*ptr >= '0'); if (!valid) *numbertext = 0; } with -Os -m4 -mb it is compiled to: _validate_number: mov.l @r4,r2 // [bb 2] tst r2,r2 bt/s .L2 mov #0,r1 mov.b @r2,r1 // [bb 3] tst r1,r1 mov #-1,r1 negc r1,r1 .L2: // [bb 4] mov #47,r3 .L3: // [bb 5] tst r1,r1 bt .L4 mov.b @r2+,r1 // [bb 6] tst r1,r1 bt/s .L8 cmp/gt r3,r1 // [bb 7] bra .L3 movt r1 .L4: mov.l r1,@r4 // [bb 8] .L8: rts nop The basic block starting with L3 (bb 5) has three different r1 inputs from [bb 2], [bb 3] and [bb 7]. When sh_treg_combine tries to trace r1 starting in [bb 5]: tracing (reg/v:SI 1 r1 [orig:185 valid ] [185]) [bb 5] set of reg not found. empty BB? [bb 4] set of reg not found (cstore) set not found - aborting trace Instead it should skip [bb 4] as it doesn't modify r1 or T bit and check [bb 3] and [bb 2]. Because the setcc insns are not the same in [bb 2], [bb 3] and [bb 7], it would try to eliminate the cstores. However, in [bb 2] there is no real cstore but a constant load, which can be replaced with a clrt or sett insn respectively. The resulting code could be something like: mov.l @r4,r2 mov #0,r1 tst r2,r2 bt/s .L2 // (*) clrt mov.b @r2,r1 tst r1,r1 movt r1 tst r1,r1 // T = !T .L2: mov #47,r3 .L3: bf .L4 mov.b @r2+,r1 tst r1,r1 bt/s .L8 bra .L3 cmp/gt r3,r1 .L4: mov.l r1,@r4 .L8: rts nop (*) The clrt insn actually has to be inserted before the conditional branch, which is impossible as it modifies the branch condition. Putting it into the delay slot however is OK, which is usually done by the DBR pass. A special "branch and set/clear T" pseudo insn would be required (requires SH2+) which produces the sequence above. A more complicated way would be to create new basic blocks. The basic block reordering or similar RTL pass and the clrt/sett optimization pass should then be able to simplify the code further to: mov.l @r4,r2 tst r2,r2 bf/s .L4 mov #0,r1 mov.b @r2,r1 tst r1,r1 bt/s .L4 mov #47,r3 .L3: mov.b @r2+,r1 tst r1,r1 bt/s .L8 cmp/gt r3,r1 bt .L3 .L4: mov.l r1,@r4 .L8: rts nop
next prev parent reply other threads:[~2013-12-05 17:54 UTC|newest] Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-11-20 20:29 [Bug target/51244] New: SH Target: Inefficient conditional branch oleg.endo@t-online.de 2011-11-22 23:36 ` [Bug target/51244] " kkojima at gcc dot gnu.org 2011-12-27 22:03 ` oleg.endo@t-online.de 2011-12-27 23:17 ` oleg.endo@t-online.de 2011-12-28 0:42 ` oleg.endo@t-online.de 2011-12-28 4:57 ` oleg.endo@t-online.de 2011-12-28 16:07 ` oleg.endo@t-online.de 2011-12-28 22:30 ` kkojima at gcc dot gnu.org 2011-12-30 22:18 ` oleg.endo@t-online.de 2012-02-26 23:36 ` olegendo at gcc dot gnu.org 2012-03-02 21:57 ` olegendo at gcc dot gnu.org 2012-03-03 12:32 ` olegendo at gcc dot gnu.org 2012-03-04 17:25 ` olegendo at gcc dot gnu.org 2012-03-05 23:13 ` olegendo at gcc dot gnu.org 2012-03-05 23:38 ` olegendo at gcc dot gnu.org 2012-03-06 8:28 ` olegendo at gcc dot gnu.org 2012-03-06 8:50 ` kkojima at gcc dot gnu.org 2012-03-06 9:48 ` olegendo at gcc dot gnu.org 2012-03-06 10:36 ` kkojima at gcc dot gnu.org 2012-03-06 10:38 ` kkojima at gcc dot gnu.org 2012-03-06 10:39 ` kkojima at gcc dot gnu.org 2012-03-06 10:40 ` kkojima at gcc dot gnu.org 2012-03-06 11:30 ` olegendo at gcc dot gnu.org 2012-03-06 23:43 ` olegendo at gcc dot gnu.org 2012-03-08 1:26 ` olegendo at gcc dot gnu.org 2012-03-08 11:12 ` kkojima at gcc dot gnu.org 2012-03-08 11:15 ` kkojima at gcc dot gnu.org 2012-03-08 11:17 ` kkojima at gcc dot gnu.org 2012-03-09 0:27 ` olegendo at gcc dot gnu.org 2012-03-09 1:45 ` kkojima at gcc dot gnu.org 2012-03-09 8:41 ` kkojima at gcc dot gnu.org 2012-03-09 10:02 ` olegendo at gcc dot gnu.org 2012-03-09 10:37 ` kkojima at gcc dot gnu.org 2012-03-11 13:18 ` olegendo at gcc dot gnu.org 2012-03-15 8:11 ` kkojima at gcc dot gnu.org 2012-03-20 1:46 ` olegendo at gcc dot gnu.org 2012-03-20 2:33 ` kkojima at gcc dot gnu.org 2012-03-20 20:41 ` olegendo at gcc dot gnu.org 2012-05-07 20:53 ` olegendo at gcc dot gnu.org 2012-05-08 21:43 ` olegendo at gcc dot gnu.org 2012-06-30 12:01 ` olegendo at gcc dot gnu.org 2012-07-02 19:24 ` olegendo at gcc dot gnu.org 2012-07-08 15:03 ` olegendo at gcc dot gnu.org 2012-07-23 22:58 ` olegendo at gcc dot gnu.org 2012-07-23 23:29 ` olegendo at gcc dot gnu.org 2012-07-26 0:20 ` olegendo at gcc dot gnu.org 2012-07-30 6:46 ` olegendo at gcc dot gnu.org 2012-08-09 15:55 ` olegendo at gcc dot gnu.org 2012-08-12 22:47 ` olegendo at gcc dot gnu.org 2012-08-20 20:51 ` olegendo at gcc dot gnu.org 2012-08-30 22:54 ` olegendo at gcc dot gnu.org 2012-08-31 10:55 ` kkojima at gcc dot gnu.org 2012-08-31 15:50 ` olegendo at gcc dot gnu.org 2012-09-04 8:03 ` olegendo at gcc dot gnu.org 2012-09-23 21:36 ` [Bug target/51244] [SH] Inefficient conditional branch and code around T bit olegendo at gcc dot gnu.org 2012-09-23 21:42 ` olegendo at gcc dot gnu.org 2012-10-03 21:39 ` olegendo at gcc dot gnu.org 2012-10-12 0:41 ` olegendo at gcc dot gnu.org 2012-10-15 22:08 ` olegendo at gcc dot gnu.org 2012-11-03 12:01 ` olegendo at gcc dot gnu.org 2013-07-18 16:11 ` laurent.alfonsi at st dot com 2013-07-18 16:12 ` laurent.alfonsi at st dot com 2013-07-20 14:38 ` olegendo at gcc dot gnu.org 2013-07-23 8:21 ` laurent.alfonsi at st dot com 2013-07-27 19:28 ` olegendo at gcc dot gnu.org 2013-07-28 8:51 ` olegendo at gcc dot gnu.org 2013-07-28 12:26 ` olegendo at gcc dot gnu.org 2013-07-31 21:46 ` olegendo at gcc dot gnu.org 2013-08-23 0:13 ` olegendo at gcc dot gnu.org 2013-08-23 0:25 ` kkojima at gcc dot gnu.org 2013-09-24 22:43 ` olegendo at gcc dot gnu.org 2013-10-03 22:50 ` olegendo at gcc dot gnu.org 2013-10-12 20:47 ` olegendo at gcc dot gnu.org 2013-10-12 21:26 ` olegendo at gcc dot gnu.org 2013-12-05 17:54 ` olegendo at gcc dot gnu.org [this message] 2013-12-06 10:47 ` olegendo at gcc dot gnu.org 2014-05-10 20:19 ` olegendo at gcc dot gnu.org 2014-05-16 22:55 ` olegendo at gcc dot gnu.org 2014-09-13 18:48 ` olegendo at gcc dot gnu.org 2014-11-22 15:07 ` olegendo at gcc dot gnu.org 2014-11-22 15:50 ` olegendo at gcc dot gnu.org 2014-11-22 16:08 ` olegendo at gcc dot gnu.org 2014-12-01 6:50 ` olegendo at gcc dot gnu.org 2014-12-17 22:53 ` olegendo at gcc dot gnu.org 2014-12-17 23:08 ` olegendo at gcc dot gnu.org 2014-12-17 23:15 ` olegendo at gcc dot gnu.org 2014-12-24 21:56 ` olegendo at gcc dot gnu.org 2015-01-24 13:06 ` olegendo at gcc dot gnu.org 2015-03-01 19:16 ` 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-51244-4-V4pPHMVNFN@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: linkBe 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).