From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4052A3858C78; Fri, 17 Feb 2023 10:34:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4052A3858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676630062; bh=06ytBD+uy8u359yjZmFoUXcqWT/dAwahJ+NmY/8xepc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QNL8pol/pOswMifqbkhF9PotqPQLhVVjd/psn2bG/Um8HhnJHvgiphyNjFu9jRsqf 3RNf1/sQpxaPcp2Dqe4jVViw0qYCu/CLimbvC+hIxcTLZ8F1Cq7EvCM7ce8Bagxwvd 3OG348Zy+vCnuJozn1jMutNygzpX09xx4tODc56I= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/90838] Detect table-based ctz implementation Date: Fri, 17 Feb 2023 10:34:19 +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: 9.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: wilco at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.0 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=3D90838 --- Comment #14 from Jakub Jelinek --- The patch does: +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0bool=C2=A0zero_ok=C2=A0=3D=C2=A0CTZ_DE= FINED_VALUE_AT_ZERO=C2=A0(TYPE_MODE=C2=A0(type),=C2=A0ctzval)=C2=A0=3D=3D 2; + +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/*=C2=A0Skip=C2=A0if=C2=A0there=C2=A0i= s=C2=A0no=C2=A0value=C2=A0defined=C2=A0at=C2=A0zero,=C2=A0or=C2=A0if=C2=A0w= e=C2=A0can't=C2=A0easily +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return=C2=A0the=C2=A0corre= ct=C2=A0value=C2=A0for=C2=A0zero.=C2=A0=C2=A0*/ +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if=C2=A0(!zero_ok) +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return=C2=A0false; +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if=C2=A0(zero_val=C2=A0!=3D=C2=A0ctzva= l=C2=A0&&=C2=A0!(zero_val=C2=A0=3D=3D=C2=A00=C2=A0&&=C2=A0ctzval=C2=A0=3D= =3D=C2=A0type_size)) +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return=C2=A0false; For CTZ_DEFINED_VALUE_AT_ZERO =3D=3D 1 we could support it the same way but= we'd need to emit into the IL an equivalent of val =3D=3D 0 ? zero_val : .CTZ (val) (= with GIMPLE_COND and a separate bb - not sure if anything in forwprop creates new basic blocks right now), where there is a high chance that RTL opts would t= urn it back into unconditional ctz. That still wouldn't help non--mbmi x86, because CTZ_DEFINED_VALUE_AT_ZERO i= s 0 there. We could handle even that case by doing the branches around, but those would stay there in the generated code, at which point I wonder whether it would be a win. = The original code is branchless...=