From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 004D8385841E; Tue, 9 Apr 2024 15:45:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 004D8385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712677538; bh=3gifNnX2Gn+B1huFlPzLfYxhaUXarVMg8VQhAjGcVr4=; h=From:To:Subject:Date:From; b=AwHwe8P8Ma0laDd/CKaaQMiPOSCkoerH8u7S04NYw9KCcEUtxq2QX3EXMSjqPsCUa 5EcBX+Pz7Tvd8xW+y+zrHAak1zwLmPmOW1jZZVrDvbYOSwT2MHBdp2Eh6teaZNSIpR zyXf5mLyDVzwXiUX4Nk5n4dpx9B0tQu/3/WK3F5Y= From: "antoshkka at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/114660] New: Exponentiating by squaring not performed for x * y * y * y * y Date: Tue, 09 Apr 2024 15:45:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: antoshkka 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 keywords 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=3D114660 Bug ID: 114660 Summary: Exponentiating by squaring not performed for x * y * y * y * y Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- For the following code: int mul(int x, int y) { return x * y * y * y * y; } with -O2 GCC produces the frollowing assembly: mul(int, int): mov eax, edi imul eax, esi imul eax, esi imul eax, esi imul eax, esi ret However, a more optimal code could be generated with less multiplications: mul(int, int): mov eax, edi imul esi, esi imul eax, esi imul eax, esi ret Godbolt playground: https://godbolt.org/z/6dP11jPfx=