From: "Alex Hill via gcc-help" <gcc-help@gcc.gnu.org>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: GCC won`t emit my instriction
Date: Fri, 07 Jun 2019 04:42:00 -0000 [thread overview]
Message-ID: <1559882546.372025449@f463.i.mail.ru> (raw)
I need to reduce amount of branches in code. There is exist benchmark called median it have some code like:
if ( A < B )
return A = foo[i];
else
return B = foo[i];
I wrote a pattern in machine description file *.md to avoid branches:
(define_insn "smin<GPR:mode>3"
[
(set
(match_operand:GPR 0 "register_operand" "=r")
(if_then_else:GPR
(lt:GPR
(match_operand:GPR 1 "register_operand" " r")
(match_operand:GPR 2 "register_operand" " r"))
(match_dup 1)
(match_dup 2)))
]
""
"min\t%0,%1,%2"
[(set_attr "type" "move")
(set_attr "mode" "<MODE>")])
It works in case of simple comparison:
if ( A < B )
return A ;
else
return B;
GCC emit:
min a0,a0,a1 # 9 smindi3 [length = 4]
ret # 21 simple_return [length = 4]
But if i try same, but with indexed variable( array ): it won`t works:
if ( A < B )
return A = foo[i];
else
return B = foo[i];
GCC emit:
blt a0,a1,.L5 # 11 *branch_orderdi [length = 4]
sd a1,8(a2) # 18 *movdi_64bit/4 [length = 4]
mv a0,a1 # 8 *movdi_64bit/1 [length = 4]
ret # 34 simple_return [length = 4]
.L5:
sd a0,8(a2) # 13 *movdi_64bit/4 [length = 4]
ret # 28 simple_return [length = 4]
I need to GCC emit something like this:
min a0,a0,a1 # 9 smindi3 [length = 4]
sd a0,8(a2) # 18 *movdi_64bit/4 [length = 4]
ret # 34 simple_return [length = 4]
I appreciate any help, and i desperate to find a desicion, i tried to look into GIMPLE to change conditions of MIN_EXPR, but there is no(almost) any documentation, and sources are VERY puzzling((
Kind regards Alex Hill.
next reply other threads:[~2019-06-07 4:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-07 4:42 Alex Hill via gcc-help [this message]
2019-06-07 4:50 ` Jeff Law
2019-06-07 5:37 ` Re[2]: " Alex Hill via gcc-help
2019-06-07 16:34 ` Segher Boessenkool
2019-06-10 6:15 ` Re[2]: " Alex Hill via gcc-help
2019-06-10 22:20 ` Jim Wilson
2019-06-11 8:32 ` Re[4]: " Alex Hill via gcc-help
2019-06-11 20:54 ` Jim Wilson
2019-06-17 11:34 ` Re[6]: " Alex Hill via gcc-help
2019-06-17 22:01 ` Jim Wilson
2019-06-18 4:08 ` Re[8]: " Alex Hill via gcc-help
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=1559882546.372025449@f463.i.mail.ru \
--to=gcc-help@gcc.gnu.org \
--cc=hardest2005@mail.ru \
/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).