From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ADAB33850430; Mon, 6 Mar 2023 08:23:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADAB33850430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678091008; bh=9C5UKvh4DiTw1FOVboXX88Rgu8+mz5kU9Ong7o57S5A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kWtcrkDXQERhrJ9LcyIpm9igHa+70B2zNoJrXE5GI39jFQgoSYREcP9Ifnl+RnTyj i/0QQPbmhQ09FLI+ywviILHDUfAwiGsp5vHkZfwqaIY6LZ5yQ4mHgF+UWPtm0v/t8s HFfD5ovEbTquzI52Iq2kGb1woNcAQdE8bq7qEbUk= From: "crazylht at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109011] missed optimization in presence of __builtin_ctz Date: Mon, 06 Mar 2023 08:23:27 +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: crazylht at gmail dot com 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 #15 from Hongtao.liu --- (In reply to Jakub Jelinek from comment #14) > (In reply to Hongtao.liu from comment #13) > > It looks like ffs is *just* ctz with defined behavior for zero, so we c= an > > handle it exactly the same as ctz in the same pattern match((bitsize - = .CLZ > > ((x - 1) & ~x)) or .POPCOUNT ((x - 1) & ~x)) when CLZ_DEFINED_VALUE_AT_= ZERO > > 2. >=20 > 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. Oh, I see.=