From patchwork Fri Nov 17 13:47:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 166179 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp538045vqn; Fri, 17 Nov 2023 05:48:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGisiHQhmLr4ZM4h4LxSGonIVoxav7Xr4n083yoGPlSXEElv2lnNoZ7pUKdqNPoTv22tU+d X-Received: by 2002:a05:6870:1ec9:b0:1f5:ad5b:c6f4 with SMTP id pc9-20020a0568701ec900b001f5ad5bc6f4mr1693872oab.47.1700228882245; Fri, 17 Nov 2023 05:48:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700228882; cv=pass; d=google.com; s=arc-20160816; b=G4+WW9QWyegyzH26K5dHdJ30jex4Y/pQG45rHsX/8KdENsnWWpX8wX7Tv7gONGdZao G28Sq9Te/F+vb5+Lb2+D0pMdQknNw9x2quJ4FMBchx/l27j6RMZI9bFjcYi7JphaSD04 p0V710vkUomZGskc29qjpTQOn30KOWWeTgwwy7IKSursxlr1wFL5CZfhi2MQVxmOIoDK WM42DtgzSROC8qmOFK3eluQX/tWMaof1UB7HLNECsYsaq5GhP11Q4pLvmCkA9L0MZtju c+0rXj0gPAqPi9wIQLFjLuEho5iN3lrcvbocKaAkUo9RcF/Y9MhkrMgX5SDXTZ14Uyyz 8Rxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=7I29hogEm6wfPgz0WerbT8HuseJvSNXlJ6lvTsOz+js=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=M9/VS/NREOcT4h7uVmRPrWB603Zf9R6x+k746FDRxUy7/MhhLb8cnlLlhbxLfTD7qz iwbAPAywvBFmg+SJ/OeJVsAWFCZsvgoOd+wwLO6EdOpJz8CGL6rcQXiaD48BN8/phVyp HpApJQQYhFOM+AY6uidD2DxPg7QdrFRsHleIQtNvJvLmh0aecxzlqmI0+OMg1XUCmfFs /ljHl5Q/uYA8nD06ooGtsDhercO93yExc+X2c9olyAm1pBUk3Y+LwDZn5ORw3Xrxc7kA dtPVWqW3NSnbmhAjUShiyKQMgUVXwvnUTwe1p9JHKN85zYvbQg/z0gnIZLIoy3114zi0 Uxqg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NQmDdLNq; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qb6-20020a05620a650600b00778982f714dsi1777357qkn.497.2023.11.17.05.48.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 05:48:02 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NQmDdLNq; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4F163858419 for ; Fri, 17 Nov 2023 13:48:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1EF8F3858D1E for ; Fri, 17 Nov 2023 13:47:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1EF8F3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1EF8F3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700228858; cv=none; b=dhL2yOJB20FRaKyfRQeXkTn4RC0DYuV3D9ruWAy2QQuOlH22+3famaQYyk3PILsoneqAzmkrjIiDPHBEy4yLDpb1MfMpo6aabXPYYHQFDWjofg3Cpl78UX/qqV+xGqyvIcrgPbtx7lDcpaaQjv+1HDhEA0o4U63HIy1zR61vmVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700228858; c=relaxed/simple; bh=Ku43QGtDFeqDw/0SnD90UIvwNlb2YLFdYTQfEgDDhtA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Fl93jt7GCcJQXuAKbjT5V2cQpgWrD1oRPXrHehFHtzvg1+ANKJL6++WLce/IMABJRqbpUEYRQM/OZjJkhjb7TLUAntn3tD+tyOf1r/168r/yN+bPKVA5UupMw4HdLUsFmxzIppiP15Iz1OgIlYhApf/kRhZmol9gJyJPccFSLN8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700228855; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=7I29hogEm6wfPgz0WerbT8HuseJvSNXlJ6lvTsOz+js=; b=NQmDdLNqBWKLDuf4RcbvEybCZ74p3UlN9nqicdf5tMgTPfxspFsP0BsnBB5f7zzNwF+HUR B8qr5LaV6TTyIjQ18EEfBEwRgiSqj4MV1e28X0zVp/uBVOG4XkZXxoVXpPDLoXirW/U9Fh mFx/IGvAY/uG8XpB0u8RzVDNcGzyX5o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-137-R0MpQrVxOF2vlgg16KmWoQ-1; Fri, 17 Nov 2023 08:47:32 -0500 X-MC-Unique: R0MpQrVxOF2vlgg16KmWoQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 37529185A780; Fri, 17 Nov 2023 13:47:32 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2D6D5028; Fri, 17 Nov 2023 13:47:31 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AHDlTPk3134591 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 17 Nov 2023 14:47:29 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AHDlSht3134588; Fri, 17 Nov 2023 14:47:28 +0100 Date: Fri, 17 Nov 2023 14:47:28 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] match.pd: Optimize ctz/popcount/parity/ffs on extended argument [PR112566] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782819200320962101 X-GMAIL-MSGID: 1782819200320962101 Hi! ctz(ext(X)) is the same as ctz(X) in the UB on zero case (or could be also 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). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 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 different decisions when it is profitable). And clz(zext(X)) is clz(X) + bit_difference, but not sure we want to change 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) == 0 -> X == 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 argument and use it in __builtin_ia32_*zcnt_u64 instead of the int one. Jakub --- gcc/match.pd.jj 2023-11-14 10:52:16.190276041 +0100 +++ gcc/match.pd 2023-11-16 13:09:41.221275374 +0100 @@ -8672,6 +8672,50 @@ (define_operator_list SYNC_FETCH_AND_AND wi::shifted_mask (tree_to_uhwi (@1), 1, false, prec)); }))))))) +#if GIMPLE +/* ctz(ext(X)) == ctz(X). Valid just for the UB at zero cases though. */ +(simplify + (CTZ (convert@1 @0)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@1)) > TYPE_PRECISION (TREE_TYPE (@0))) + (with { combined_fn cfn = CFN_LAST; + tree type0 = TREE_TYPE (@0); + if (TREE_CODE (type0) == BITINT_TYPE) + { + if (TYPE_PRECISION (type0) > MAX_FIXED_MODE_SIZE) + cfn = CFN_CTZ; + else + type0 + = build_nonstandard_integer_type (TYPE_PRECISION (type0), + 1); + } + type0 = unsigned_type_for (type0); + if (cfn == CFN_LAST + && direct_internal_fn_supported_p (IFN_CTZ, type0, + OPTIMIZE_FOR_BOTH)) + cfn = CFN_CTZ; + if (cfn == CFN_LAST + && TYPE_PRECISION (TREE_TYPE (@1)) > BITS_PER_WORD + && !direct_internal_fn_supported_p (IFN_CTZ, + TREE_TYPE (@1), + OPTIMIZE_FOR_BOTH)) + { + if (TYPE_PRECISION (type0) + == TYPE_PRECISION (unsigned_type_node)) + cfn = CFN_BUILT_IN_CTZ; + else if (TYPE_PRECISION (type0) + == TYPE_PRECISION (long_long_unsigned_type_node)) + cfn = CFN_BUILT_IN_CTZLL; + } } + (if (cfn == CFN_CTZ) + (IFN_CTZ (convert:type0 @0)) + (if (cfn == CFN_BUILT_IN_CTZ) + (BUILT_IN_CTZ (convert:type0 @0)) + (if (cfn == CFN_BUILT_IN_CTZLL) + (BUILT_IN_CTZLL (convert:type0 @0)))))))) +#endif + /* POPCOUNT simplifications. */ /* popcount(X) + popcount(Y) is popcount(X|Y) when X&Y must be zero. */ (simplify @@ -8742,6 +8786,50 @@ (define_operator_list SYNC_FETCH_AND_AND (popcount:s @1)) (popcount (log2 @0 @1))))) +#if GIMPLE +/* popcount(zext(X)) == popcount(X). */ +(simplify + (POPCOUNT (convert@1 @0)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_UNSIGNED (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@1)) > TYPE_PRECISION (TREE_TYPE (@0))) + (with { combined_fn cfn = CFN_LAST; + tree type0 = TREE_TYPE (@0); + if (TREE_CODE (type0) == BITINT_TYPE) + { + if (TYPE_PRECISION (type0) > MAX_FIXED_MODE_SIZE) + cfn = CFN_POPCOUNT; + else + type0 + = build_nonstandard_integer_type (TYPE_PRECISION (type0), + 1); + } + if (cfn == CFN_LAST + && direct_internal_fn_supported_p (IFN_POPCOUNT, type0, + OPTIMIZE_FOR_BOTH)) + cfn = CFN_POPCOUNT; + if (cfn == CFN_LAST + && TYPE_PRECISION (TREE_TYPE (@1)) > BITS_PER_WORD + && !direct_internal_fn_supported_p (IFN_POPCOUNT, + TREE_TYPE (@1), + OPTIMIZE_FOR_BOTH)) + { + if (TYPE_PRECISION (type0) + == TYPE_PRECISION (unsigned_type_node)) + cfn = CFN_BUILT_IN_POPCOUNT; + else if (TYPE_PRECISION (type0) + == TYPE_PRECISION (long_long_unsigned_type_node)) + cfn = CFN_BUILT_IN_POPCOUNTLL; + } } + (if (cfn == CFN_POPCOUNT) + (IFN_POPCOUNT (convert:type0 @0)) + (if (cfn == CFN_BUILT_IN_POPCOUNT) + (BUILT_IN_POPCOUNT (convert:type0 @0)) + (if (cfn == CFN_BUILT_IN_POPCOUNTLL) + (BUILT_IN_POPCOUNTLL (convert:type0 @0)))))))) +#endif + /* PARITY simplifications. */ /* parity(~X) is parity(X). */ (simplify @@ -8780,6 +8868,54 @@ (define_operator_list SYNC_FETCH_AND_AND (bit_xor (PARITY:s @0) (PARITY:s @1)) (PARITY (bit_xor @0 @1))) +#if GIMPLE +/* parity(zext(X)) == parity(X). */ +/* parity(sext(X)) == parity(X) if the difference in precision is even. */ +(simplify + (PARITY (convert@1 @0)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@1)) > TYPE_PRECISION (TREE_TYPE (@0)) + && (TYPE_UNSIGNED (TREE_TYPE (@0)) + || ((TYPE_PRECISION (TREE_TYPE (@1)) + - TYPE_PRECISION (TREE_TYPE (@0))) & 1) == 0)) + (with { combined_fn cfn = CFN_LAST; + tree type0 = TREE_TYPE (@0); + if (TREE_CODE (type0) == BITINT_TYPE) + { + if (TYPE_PRECISION (type0) > MAX_FIXED_MODE_SIZE) + cfn = CFN_PARITY; + else + type0 + = build_nonstandard_integer_type (TYPE_PRECISION (type0), + 1); + } + type0 = unsigned_type_for (type0); + if (cfn == CFN_LAST + && direct_internal_fn_supported_p (IFN_PARITY, type0, + OPTIMIZE_FOR_BOTH)) + cfn = CFN_PARITY; + if (cfn == CFN_LAST + && TYPE_PRECISION (TREE_TYPE (@1)) > BITS_PER_WORD + && !direct_internal_fn_supported_p (IFN_PARITY, + TREE_TYPE (@1), + OPTIMIZE_FOR_BOTH)) + { + if (TYPE_PRECISION (type0) + == TYPE_PRECISION (unsigned_type_node)) + cfn = CFN_BUILT_IN_PARITY; + else if (TYPE_PRECISION (type0) + == TYPE_PRECISION (long_long_unsigned_type_node)) + cfn = CFN_BUILT_IN_PARITYLL; + } } + (if (cfn == CFN_PARITY) + (IFN_PARITY (convert:type0 @0)) + (if (cfn == CFN_BUILT_IN_PARITY) + (BUILT_IN_PARITY (convert:type0 @0)) + (if (cfn == CFN_BUILT_IN_PARITYLL) + (BUILT_IN_PARITYLL (convert:type0 @0)))))))) +#endif + /* a != 0 ? FUN(a) : 0 -> Fun(a) for some builtin functions. */ (for func (POPCOUNT BSWAP FFS PARITY) (simplify @@ -8987,8 +9123,7 @@ (define_operator_list SYNC_FETCH_AND_AND (plus (CTZ:type (convert:utype @0)) { build_one_cst (type); })))) #endif -(for ffs (BUILT_IN_FFS BUILT_IN_FFSL BUILT_IN_FFSLL - BUILT_IN_FFSIMAX) +(for ffs (FFS) /* __builtin_ffs (X) == 0 -> X == 0. __builtin_ffs (X) == 6 -> (X & 63) == 32. */ (for cmp (eq ne) @@ -9036,6 +9171,50 @@ (define_operator_list SYNC_FETCH_AND_AND { build_zero_cst (TREE_TYPE (@0)); })))))))) #if GIMPLE +/* ffs(ext(X)) == ffs(X). */ +(simplify + (FFS (convert@1 @0)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@1)) > TYPE_PRECISION (TREE_TYPE (@0))) + (with { combined_fn cfn = CFN_LAST; + tree type0 = TREE_TYPE (@0); + if (TREE_CODE (type0) == BITINT_TYPE) + { + if (TYPE_PRECISION (type0) > MAX_FIXED_MODE_SIZE) + cfn = CFN_FFS; + else + type0 + = build_nonstandard_integer_type (TYPE_PRECISION (type0), + 0); + } + type0 = signed_type_for (type0); + if (cfn == CFN_LAST + && direct_internal_fn_supported_p (IFN_FFS, type0, + OPTIMIZE_FOR_BOTH)) + cfn = CFN_FFS; + if (cfn == CFN_LAST + && TYPE_PRECISION (TREE_TYPE (@1)) > BITS_PER_WORD + && !direct_internal_fn_supported_p (IFN_FFS, + TREE_TYPE (@1), + OPTIMIZE_FOR_BOTH)) + { + if (TYPE_PRECISION (type0) + == TYPE_PRECISION (integer_type_node)) + cfn = CFN_BUILT_IN_FFS; + else if (TYPE_PRECISION (type0) + == TYPE_PRECISION (long_long_integer_type_node)) + cfn = CFN_BUILT_IN_FFSLL; + } } + (if (cfn == CFN_FFS) + (IFN_FFS (convert:type0 @0)) + (if (cfn == CFN_BUILT_IN_FFS) + (BUILT_IN_FFS (convert:type0 @0)) + (if (cfn == CFN_BUILT_IN_FFSLL) + (BUILT_IN_FFSLL (convert:type0 @0)))))))) +#endif + +#if GIMPLE /* Simplify: a = op a1 --- gcc/testsuite/gcc.dg/pr112566-1.c.jj 2023-11-16 13:29:23.063761320 +0100 +++ gcc/testsuite/gcc.dg/pr112566-1.c 2023-11-16 13:35:14.459852714 +0100 @@ -0,0 +1,14 @@ +/* PR tree-optimization/112566 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-additional-options "-mbmi2 -mlzcnt -mpopcnt" { target i?86-*-* x86_64-*-* } } */ +/* { dg-final { scan-tree-dump-not "ll \\\(" "optimized" { target ia32 } } } */ +/* { dg-final { scan-tree-dump-not "\\\(long long (unsigned )?int\\\)" "optimized" { target ia32 } } } */ + +int foo (unsigned int x) { return __builtin_ctzll (x); } +int bar (unsigned int x) { return __builtin_popcountll (x); } +int baz (unsigned int x) { return __builtin_parityll (x); } +int qux (int x) { return __builtin_ffsll (x); } +int corge (int x) { return __builtin_ctzll (x); } +int garply (int x) { return __builtin_parityll (x); } +int fred (unsigned int x) { return __builtin_ffsll (x); } --- gcc/testsuite/gcc.dg/pr112566-2.c.jj 2023-11-16 13:32:30.854138101 +0100 +++ gcc/testsuite/gcc.dg/pr112566-2.c 2023-11-16 13:34:14.727687104 +0100 @@ -0,0 +1,12 @@ +/* PR tree-optimization/112566 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-O2 -fdump-tree-ccp2" } */ +/* { dg-final { scan-tree-dump-not "\\\((unsigned )?_BitInt\\\(512\\\)\\\)" "ccp2" } } */ + +int foo (unsigned _BitInt(256) x) { return __builtin_ctzg ((unsigned _BitInt(512)) x); } +int bar (unsigned _BitInt(256) x) { return __builtin_popcountg ((unsigned _BitInt(512)) x); } +int baz (unsigned _BitInt(256) x) { return __builtin_parityg ((unsigned _BitInt(512)) x); } +int qux (_BitInt(256) x) { return __builtin_ffsg ((_BitInt(512)) x); } +int corge (_BitInt(256) x) { return __builtin_ctzg ((unsigned _BitInt(512)) x); } +int garply (_BitInt(256) x) { return __builtin_parityg ((unsigned _BitInt(512)) x); } +int fred (unsigned _BitInt(256) x) { return __builtin_ffsg ((_BitInt(512)) x); } --- gcc/testsuite/gcc.target/i386/pr78057.c.jj 2020-01-14 20:02:47.876593462 +0100 +++ gcc/testsuite/gcc.target/i386/pr78057.c 2023-11-17 14:27:39.120666182 +0100 @@ -5,7 +5,7 @@ extern void link_error (void); int -foo (int x) +foo (int x, long long y) { if (__builtin_ia32_tzcnt_u16 (16) != 4 || __builtin_ia32_tzcnt_u16 (0) != 16 @@ -24,13 +24,14 @@ foo (int x) ) link_error (); x += 2; - if (x == 0) + y += 2; + if (x == 0 || y == 0) return 5; return __builtin_ia32_tzcnt_u32 (x) + __builtin_ia32_lzcnt_u32 (x) #ifdef __x86_64__ - + __builtin_ia32_tzcnt_u64 (x) - + __builtin_ia32_lzcnt_u64 (x) + + __builtin_ia32_tzcnt_u64 (y) + + __builtin_ia32_lzcnt_u64 (y) #endif ; }