From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CBDC93858C5E; Mon, 5 Feb 2024 11:38:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBDC93858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707133087; bh=ZMn14QoLqj1dSeVgGcXaerJI6qrGT4GacjI0ng1KgqA=; h=From:To:Subject:Date:From; b=NsV0KKLTzI5vSE/056Di77Hrq2LlRcyAwTVqkb6AQ5pQvwpIudfqmHup/soRuhARA yn18y0nq9pMFCwjKvZbFCAOEa24Fum+T97JZ7+5sbrbae4j2lb8EAHJtqcI1TM9zgN izOL3Sr9QMtKDyQybyTaDEc7zdNLqbzeDc1zp8pA= From: "chfast at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/113764] New: [X86] Generates lzcnt when bsr is sufficient Date: Mon, 05 Feb 2024 11:38:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: chfast 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=3D113764 Bug ID: 113764 Summary: [X86] Generates lzcnt when bsr is sufficient Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: chfast at gmail dot com Target Milestone: --- When lzcnt instructions is enabled (-mlzcnt) the compiler generates lzcnt f= or __builtin_clz() in the context where the bsr instruction is sufficient and better. unsigned bsr(unsigned x) { return __builtin_clz(x) ^ 31; } bsr: xor eax, eax lzcnt eax, edi xor eax, 31 ret Without -mlzcnt the generated code is optimal. bsr: bsr eax, edi ret https://godbolt.org/z/5qcTq18nr=