public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "koenigni at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/98425] New: Superfluous sign-extend for constrained integer Date: Wed, 23 Dec 2020 10:19:15 +0000 [thread overview] Message-ID: <bug-98425-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98425 Bug ID: 98425 Summary: Superfluous sign-extend for constrained integer Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: koenigni at gcc dot gnu.org Target Milestone: --- Hello everyone, A small missed optimization I noticed while toying around with the difference between signed and unsigned integers. The following code int baz(int *p, int i) { int j; if (i >= 0) { j = i + 4; return p[j]; } else __builtin_unreachable(); } is compiled with `gcc -O3 -S` to baz: addl $4, %esi movslq %esi, %rsi movl (%rdi,%rsi,4), %eax ret The movslq instruction is unnecessary since i is constrained to never be negative and therefore no sign extension is needed. This probably also prevents the addl instructions to be removed and the offset being put into the movl. For comparison, clang (with the same options) compiles the code to baz: movl %esi, %eax movl 16(%rdi, %rax, 4), %eax ret Optimal would probably be baz: movl 16(%rdi, %rsi, 4), %eax ret
next reply other threads:[~2020-12-23 10:19 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-23 10:19 koenigni at gcc dot gnu.org [this message] 2020-12-23 10:28 ` [Bug rtl-optimization/98425] " pinskia at gcc dot gnu.org 2020-12-23 10:30 ` pinskia at gcc dot gnu.org 2020-12-23 10:30 ` jakub at gcc dot gnu.org 2020-12-23 10:40 ` jakub at gcc dot gnu.org 2020-12-23 10:48 ` koenigni 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-98425-4@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).