From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E54EB3858D35; Mon, 6 Mar 2023 08:11:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E54EB3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678090274; bh=vBy0VfvaVEpwwpggIn9hYiO5Vq1VsGp0Htffn5YjK/o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=b6U8hxrdukVh0q2ApY4nkuyV3tErLhS+IM5upVQg3nDqo1rJql8/yLl/FaW0R86oK XV9sjUwnclkc4XBT+bujCEYYnZt+6x6pfSX53vHWKp7cp9BDt8F0wFKBGRw1Dd1Plq rAuHxvVANECVUVcJNwXvWuA0NUhw8Zevcyif0dZI= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109011] missed optimization in presence of __builtin_ctz Date: Mon, 06 Mar 2023 08:11:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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=3D109011 --- Comment #14 from Jakub Jelinek --- (In reply to Hongtao.liu from comment #13) > It looks like ffs is *just* ctz with defined behavior for zero, so we can > handle it exactly the same as ctz in the same pattern match((bitsize - .C= LZ > ((x - 1) & ~x)) or .POPCOUNT ((x - 1) & ~x)) when CLZ_DEFINED_VALUE_AT_ZE= RO > 2. No, ffs(x) is ctz(x) + 1 for all x !=3D 0, and 0 for x =3D=3D 0. But yes, = we can generally handle it similarly. Let me attach a patch.=