public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "denis.campredon at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107859] New: Fail to optimize rot13 Date: Thu, 24 Nov 2022 13:32:03 +0000 [thread overview] Message-ID: <bug-107859-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107859 Bug ID: 107859 Summary: Fail to optimize rot13 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: denis.campredon at gmail dot com Target Milestone: --- Compiled with -O2, the following functions produce different assembly although they compute the same things: ---------------------------- unsigned rot13_1(unsigned c) { if(c >= 'A' && c <= 'Z') return 'A' + ((c -'A') + 13)%26; __builtin_unreachable(); } unsigned rot13_2(unsigned c) { if (c >= 'A' && c <= 'M' ) return c + 13; else if (c >= 'N' && c <= 'Z' ) return c - 13; __builtin_unreachable(); } unsigned rot13_3(unsigned c) { if(c >= 'A' && c <= 'Z') return c + (c > 'Z' - 13 ? -13 : 13); __builtin_unreachable(); } unsigned rot13_4(unsigned c) { if(c >= 'A' && c <= 'Z') return c + 13 + (c > 'Z' - 13 ? -26 : 0); __builtin_unreachable(); } ------------------------------ rot13_1(unsigned int): lea edx, [rdi-52] mov rax, rdx imul rdx, rdx, 1321528399 shr rdx, 35 imul edx, edx, 26 sub eax, edx add eax, 65 ret rot13_2(unsigned int): lea edx, [rdi-65] lea eax, [rdi+13] sub edi, 13 cmp edx, 12 cmova eax, edi ret rot13_3(unsigned int): cmp edi, 78 sbb eax, eax and eax, 26 lea eax, [rax-13+rdi] ret rot13_4(unsigned int): cmp edi, 78 sbb eax, eax not eax and eax, -26 lea eax, [rax+13+rdi] ret
reply other threads:[~2022-11-24 13:32 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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-107859-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).