From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 99B623858C5F; Thu, 8 Feb 2024 00:35:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99B623858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707352514; bh=Nz2PcKZd1ihtBckh3R8HwhzqA+jBR+a3VrxDvsQAr+8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eWzXRbRLmN0eTUT3C+As/yFlYZV7MMekMXR7Q3iJ1TqwYcb5bq3msp7xPlyUMZBrM 2CuTM3Kxk/sZZAliHgeXOYUKZvW8AD1JCEEgNyLHIhEkh7k+UeO12m8iSKzqtr5aW2 GF1DPivsNj3X0Lymg8t43FrzjPnXBMAfQ5pAvZow= From: "roger at nextmovesoftware dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/113764] [X86] Generates lzcnt when bsr is sufficient Date: Thu, 08 Feb 2024 00:35:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: roger at nextmovesoftware dot com X-Bugzilla-Status: NEW 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: cc bug_status everconfirmed cf_reconfirmed_on Message-ID: In-Reply-To: References: 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 Roger Sayle changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |roger at nextmovesoftware = dot com Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed| |2024-02-08 --- Comment #1 from Roger Sayle --- Confirmed. This issue has two parts. The first is that the bsr_1 pattern = (and variants) is (are) conditional on !TARGET_LZCNT, so the bsrl instruction is= n't currently available with -mlzcnt. The second is that the middle-end doesn't have a preferred canonical RTL representation for this idiom, but all three= of the following equivalent functions should generate identical code: unsigned bsr1(unsigned x) { return __builtin_clz(x) ^ 31; } unsigned bsr2(unsigned x) { return 31 - __builtin_clz(x); } unsigned bsr3(unsigned x) { return ~__builtin_clz(x) & 31; } [Note that the tree-ssa optimizers do transform bsr3 into bsr1]. A suitable fix would be to add the equivalent clz(x)^31 variant pattern to i386.md as a "synonymous" define_insn pattern.=