public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rzinsly at ventanamicro dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/108038] GCC generates poor code for select of consecutive constants on riscv-64 Date: Wed, 14 Dec 2022 15:51:03 +0000 [thread overview] Message-ID: <bug-108038-4-GHyzgINxkz@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-108038-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108038 --- Comment #1 from Raphael M Zinsly <rzinsly at ventanamicro dot com> --- (In reply to Jeffrey A. Law from comment #0) > testGT: > sgt a0,a0,a1 # 25 [c=4 l=4] *sgt_didi > xori a0,a0,1 # 27 [c=4 l=4] xordi3/1 > addi a0,a0,2 # 16 [c=4 l=4] adddi3/1 > ret # 35 [c=0 l=4] simple_return > > > But ISTM we could generate this instead: > > testGT: > sgt a0,a1,a0 # 24 [c=4 l=4] *riscv.md:2535 > addi a0,a0,2 # 16 [c=4 l=4] adddi3/1 > ret # 32 [c=0 l=4] simple_return Unless I'm missing something this seems wrong: 'sgt a0,a0,a1' with 'xori a0,a0,1' would be equivalent to 'sge a0,a1,a0' or to 'sle a0,a0,a1' and not to 'sgt a0,a1,a0'. For x == y the result would be 2 with your asm. > We can invert the condition and swap the operands with something like this: > > (define_insn "" > [(set (match_operand:GPR 0 "register_operand" "=r") > (any_le:GPR (match_operand:X 1 "register_operand" " r") > (match_operand:X 2 "register_operand" "r")))] > "" > "sgt<u>\t%0,%2,%1" > [(set_attr "type" "slt") > (set_attr "mode" "<X:MODE>")]) This works as you intended. However, I think the right patter should be: (define_insn "*sge<u>_<X:mode><GPR:mode>_inv" [(set (match_operand:GPR 0 "register_operand" "=r") (any_le:GPR (match_operand:X 1 "register_operand" " r") (match_operand:X 2 "register_operand" "r")))] "" "sge<u>\t%0,%2,%1" [(set_attr "type" "slt") (set_attr "mode" "<X:MODE>")]) It produces the output: testGT: sge a0,a1,a0 # 24 [c=4 l=4] *sge_didi_inv addi a0,a0,2 # 16 [c=4 l=4] adddi3/1 ret # 32 [c=0 l=4] simple_return
prev parent reply other threads:[~2022-12-14 15:51 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-09 21:17 [Bug target/108038] New: GCC generates poor code for select of consecutive constants law at gcc dot gnu.org 2022-12-14 15:51 ` rzinsly at ventanamicro dot com [this message]
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-108038-4-GHyzgINxkz@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).