From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 196533858409; Fri, 17 Nov 2023 14:11:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 196533858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700230297; bh=f7aD2nCoKvUNAjxrFQaojweoDQG48B1HXbz/Rftjt+I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=SChRKOpdmKOKy6/6JldNAKSgVYnMBVFZqQZmwZUnYxVgNRg8Z3fo66ZPsgcfedcdo grwUcJSdDUKnID+H30/fbyBXPiV9g+8E+BnTdFFwd0EwcR/aE5AMtxy1Q1Y0pZL8D+ EQaUV01CtcVwyq8UuCIvBAZyiIiBFPlGKf5yB/FQ= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/83171] __builtin_popcountl ((unsigned long long)unsigned_var) is not being optimized to __builtin_popcount (unsigned_var) Date: Fri, 17 Nov 2023 14:11:34 +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: 7.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: cvs-commit at gcc dot gnu.org 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: 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=3D83171 --- Comment #4 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:6dd4c703be17fa5dd56136d067e7fdc4a61584b3 commit r14-5557-g6dd4c703be17fa5dd56136d067e7fdc4a61584b3 Author: Jakub Jelinek Date: Fri Nov 17 15:10:51 2023 +0100 match.pd: Optimize ctz/popcount/parity/ffs on extended argument [PR1125= 66] ctz(ext(X)) is the same as ctz(X) in the UB on zero case (or could be a= lso in the 2 argument case on large BITINT_TYPE by preserving the argument,= not implemented in this patch), popcount(zext(X)) is the same as popcount(X), parity(zext(X)) is the same as parity(X), parity(sext(X)) is the same as parity(X) provided the bit difference between the extended and unextended types is even, ffs(ext(X)) is the same as ffs(X). The following patch optimizes those in match.pd if those are beneficial (always in the large BITINT_TYPE case, or if the narrower type has optab and the wider doesn't, or the wider is larger than word and narrower is one of the standard argument sizes (tested just int and long long, as long is on most targets same bitsize as one of those two). Joseph in the PR mentioned that ctz(narrow(X)) is the same as ctz(X) if UB on 0, but that can be handled incrementally (and would need diffe= rent decisions when it is profitable). And clz(zext(X)) is clz(X) + bit_difference, but not sure we want to ch= ange that in match.pd at all, perhaps during insn selection? 2023-11-17 Jakub Jelinek PR tree-optimization/112566 PR tree-optimization/83171 * match.pd (ctz(ext(X)) -> ctz(X), popcount(zext(X)) -> popcount(X), parity(ext(X)) -> parity(X), ffs(ext(X)) -> ffs(X)): New simplifications. ( __builtin_ffs (X) =3D=3D 0 -> X =3D=3D 0): Use FFS rather than BUILT_IN_FFS BUILT_IN_FFSL BUILT_IN_FFSLL BUILT_IN_FFSIMAX. * gcc.dg/pr112566-1.c: New test. * gcc.dg/pr112566-2.c: New test. * gcc.target/i386/pr78057.c (foo): Pass another long long argum= ent and use it in __builtin_ia32_*zcnt_u64 instead of the int one.=