From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BE1513858D39; Mon, 6 Mar 2023 07:59:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE1513858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678089583; bh=0Ds6jHRh/tNLphElCIn1LwOCzoIRPQqq7s2I3Gmu+4c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ip9+zeSa7hTon0LdGm2+dfMff+tqMfHULPX+2KgxQHYVaz8spYJtg4cvnJOEQI7Fp T34NuyYe64ABOOTgHLwTvWjDgFxt8XZPA4boyHw5P9+g7qozgo5fHsTBlVYhIZKoDl 6k3neggeJQ6s/42TiYRLM7GnLwZGYzVn0Rsfh83M= 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 07:59:43 +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 #13 from Hongtao.liu --- (In reply to Jakub Jelinek from comment #12) > (In reply to Hongtao.liu from comment #11) > > (In reply to Jakub Jelinek from comment #3) > > > Seems they are vectorizing __builtin_ctz (x) as bitsize - .CLZ ((x - = 1) & > > > ~x) for CLZ_DEFINED_VALUE_AT_ZERO 2 with value bitsize. > > > Perhaps we should pattern match it in tree-vect-patterns.cc that way = if clz > > > is vectorizable (it is with -mavx512cd) and ctz is not. > >=20 > > Yes, I'm going to add a pattern match named vect_recog_ctz_as_clz_or_po= pcnt. > >=20 > > BTW, It looks like only x86 have vector clz but not ctz, for other targ= ets, > > they either have both or neither. >=20 > I have already the patch half written. Yes, for clz, but various other > targets don't have ffs and do have clz etc. 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 - .CLZ= ((x - 1) & ~x)) or .POPCOUNT ((x - 1) & ~x)) when CLZ_DEFINED_VALUE_AT_ZERO 2.=