From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BEC8F384640E; Mon, 16 Nov 2020 17:40:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEC8F384640E From: "miguel.ojeda.sandonis at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97856] New: Missed optimization: repeated call Date: Mon, 16 Nov 2020 17:40:55 +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: miguel.ojeda.sandonis 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 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, 16 Nov 2020 17:40:55 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97856 Bug ID: 97856 Summary: Missed optimization: repeated call Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: miguel.ojeda.sandonis at gmail dot com Target Milestone: --- For code such as: void f(int); void g(int v) { switch (v) { case 1: f(1); case 2: f(2); case 3: f(3); default: f(4); } } GCC generates for e.g. x86_64: g(int): subq $8, %rsp cmpl $2, %edi je .L2 cmpl $3, %edi je .L3 cmpl $1, %edi je .L13 movl $4, %edi addq $8, %rsp jmp f(int) .L13: call f(int) .L2: movl $2, %edi call f(int) .L3: movl $3, %edi call f(int) movl $4, %edi addq $8, %rsp jmp f(int) Repeating the `f(4);` call can be avoided by reordering the cases, reducing code size.=