From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C132C3836013; Thu, 24 Nov 2022 13:32:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C132C3836013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669296723; bh=yIo3x9SjNZgb18Wt7QadnY5mgDRe30478jIBwBpRkQo=; h=From:To:Subject:Date:From; b=RiH2KmHK38y7t/baFuv6blBH1TPBImWv/LIjTE+8p3lTBN7gPI9NWPbS5ca0VvLF9 rXLsQXC/qqhsGrgJUMUXhzGaLKrrcjojLG+YSBBsugX3ekOU11KLHNrqEFbHKNhjA2 9u9SrjH0b76f7HUL/8Wfk/C++fOQr0ujde77x3PI= From: "denis.campredon at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: denis.campredon at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107859 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 altho= ugh they compute the same things: ---------------------------- unsigned rot13_1(unsigned c) { if(c >=3D 'A' && c <=3D 'Z') return 'A' + ((c -'A') + 13)%26; __builtin_unreachable(); } unsigned rot13_2(unsigned c) { if (c >=3D 'A' && c <=3D 'M' ) return c + 13; else if (c >=3D 'N' && c <=3D 'Z' ) return c - 13; __builtin_unreachable(); } unsigned rot13_3(unsigned c) { if(c >=3D 'A' && c <=3D 'Z') return c + (c > 'Z' - 13 ? -13 : 13); __builtin_unreachable(); } unsigned rot13_4(unsigned c) { if(c >=3D 'A' && c <=3D '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=