public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/110717] Double-word sign-extension missed-optimization Date: Mon, 30 Oct 2023 16:18:59 +0000 [thread overview] Message-ID: <bug-110717-4-QnTRxvc1Sz@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110717-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110717 --- Comment #16 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>: https://gcc.gnu.org/g:31cc9824d1cd5e0f7fa145d0831a923479333cd6 commit r14-5013-g31cc9824d1cd5e0f7fa145d0831a923479333cd6 Author: Roger Sayle <roger@nextmovesoftware.com> Date: Mon Oct 30 16:17:42 2023 +0000 ARC: Improved ARC rtx_costs/insn_cost for SHIFTs and ROTATEs. This patch overhauls the ARC backend's insn_cost target hook, and makes some related improvements to rtx_costs, BRANCH_COST, etc. The primary goal is to allow the backend to indicate that shifts and rotates are slow (discouraged) when the CPU doesn't have a barrel shifter. I should also acknowledge Richard Sandiford for inspiring the use of set_cost in this rewrite of arc_insn_cost; this implementation borrows heavily for the target hooks for AArch64 and ARM. The motivating example is derived from PR rtl-optimization/110717. struct S { int a : 5; }; unsigned int foo (struct S *p) { return p->a; } With a barrel shifter, GCC -O2 generates the reasonable: foo: ldb_s r0,[r0] asl_s r0,r0,27 j_s.d [blink] asr_s r0,r0,27 What's interesting is that during combine, the middle-end actually has two shifts by three bits, and a sign-extension from QI to SI. Trying 8, 9 -> 11: 8: r158:SI=r157:QI#0<<0x3 REG_DEAD r157:QI 9: r159:SI=sign_extend(r158:SI#0) REG_DEAD r158:SI 11: r155:SI=r159:SI>>0x3 REG_DEAD r159:SI Whilst it's reasonable to simplify this to two shifts by 27 bits when the CPU has a barrel shifter, it's actually a significant pessimization when these shifts are implemented by loops. This combination can be prevented if the backend provides accurate-ish estimates for insn_cost. Previously, without a barrel shifter, GCC -O2 -mcpu=em generates: foo: ldb_s r0,[r0] mov lp_count,27 lp 2f add r0,r0,r0 nop 2: # end single insn loop mov lp_count,27 lp 2f asr r0,r0 nop 2: # end single insn loop j_s [blink] which contains two loops and requires about ~113 cycles to execute. With this patch to rtx_cost/insn_cost, GCC -O2 -mcpu=em generates: foo: ldb_s r0,[r0] mov_s r2,0 ;3 add3 r0,r2,r0 sexb_s r0,r0 asr_s r0,r0 asr_s r0,r0 j_s.d [blink] asr_s r0,r0 which requires only ~6 cycles, for the shorter shifts by 3 and sign extension. 2023-10-30 Roger Sayle <roger@nextmovesoftware.com> gcc/ChangeLog * config/arc/arc.cc (arc_rtx_costs): Improve cost estimates. Provide reasonable values for SHIFTS and ROTATES by constant bit counts depending upon TARGET_BARREL_SHIFTER. (arc_insn_cost): Use insn attributes if the instruction is recognized. Avoid calling get_attr_length for type "multi", i.e. define_insn_and_split patterns without explicit type. Fall-back to set_rtx_cost for single_set and pattern_cost otherwise. * config/arc/arc.h (COSTS_N_BYTES): Define helper macro. (BRANCH_COST): Improve/correct definition. (LOGICAL_OP_NON_SHORT_CIRCUIT): Preserve previous behavior.
next prev parent reply other threads:[~2023-10-30 16:19 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-18 14:32 [Bug rtl-optimization/110717] New: " jakub at gcc dot gnu.org 2023-07-18 14:33 ` [Bug rtl-optimization/110717] " jakub at gcc dot gnu.org 2023-07-18 14:54 ` jakub at gcc dot gnu.org 2023-07-19 6:38 ` rguenth at gcc dot gnu.org 2023-07-19 8:55 ` ubizjak at gmail dot com 2023-07-19 9:00 ` jakub at gcc dot gnu.org 2023-07-19 9:30 ` ubizjak at gmail dot com 2023-07-20 18:56 ` cvs-commit at gcc dot gnu.org 2023-07-20 19:03 ` ubizjak at gmail dot com 2023-07-20 19:19 ` jakub at gcc dot gnu.org 2023-07-20 19:21 ` jakub at gcc dot gnu.org 2023-07-21 9:06 ` jakub at gcc dot gnu.org 2023-07-21 10:53 ` segher at gcc dot gnu.org 2023-07-21 16:28 ` segher at gcc dot gnu.org 2023-07-21 16:46 ` pinskia at gcc dot gnu.org 2023-08-04 15:26 ` cvs-commit at gcc dot gnu.org 2023-10-30 16:18 ` cvs-commit at gcc dot gnu.org [this message] 2023-12-13 13:37 ` cvs-commit at gcc dot gnu.org 2024-05-07 7:41 ` rguenth 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-110717-4-QnTRxvc1Sz@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).