From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A410A3858C27; Mon, 25 Oct 2021 12:53:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A410A3858C27 From: "jengelh at inai dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102929] New: [missed optimization] two ways to rounddown-to-next-multiple Date: Mon, 25 Oct 2021 12:53:36 +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: 11.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jengelh at inai dot de 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Oct 2021 12:53:36 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102929 Bug ID: 102929 Summary: [missed optimization] two ways to rounddown-to-next-multiple Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jengelh at inai dot de Target Milestone: --- Input =3D=3D=3D=3D=3D unsigned long calc(unsigned long x, unsigned long y) { return x/y*y; } unsigned long calc2(unsigned long x, unsigned long y) { return x - x % y; } Observed =3D=3D=3D=3D=3D=3D=3D=3D =C2=BB g++ -O3 -c x.c; objdump -Mintel -d x.o gcc version 11.2.1 20210816 [revision 056e324ce46a7924b5cf10f61010cf9dd2ca1= 0e9] (SUSE Linux) x86_64 0000000000000000 <_Z4calcmm>: 0: 48 89 f8 mov rax,rdi 3: 31 d2 xor edx,edx 5: 48 f7 f6 div rsi 8: 48 0f af c6 imul rax,rsi c: c3 ret=20=20=20=20 d: 0f 1f 00 nop DWORD PTR [rax] 0000000000000010 <_Z5calc2mm>: 10: 48 89 f8 mov rax,rdi 13: 31 d2 xor edx,edx 15: 48 f7 f6 div rsi 18: 48 89 f8 mov rax,rdi 1b: 48 29 d0 sub rax,rdx 1e: c3 ret=20=20=20=20 Expected =3D=3D=3D=3D=3D=3D=3D=3D I do not see any obvious differences in the outcome of the two C functions,= so I would expect that, ideally, both should lead to the same asm. (Either by making calc use div-mov-sub, or by making calc2 using div-imul; whichever happens to be determined more beneficial as per the machine descriptions).=