From patchwork Thu Jan 4 09:00:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 184947 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5494423dyb; Thu, 4 Jan 2024 01:03:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8c2hKWDOI9VICtQaEecwuAM5WP+JZK2rAtBQsSu70Pa3JaNhiHqMwoEciU5YbhA+IrXgP X-Received: by 2002:a05:6214:2684:b0:67f:2d9b:2753 with SMTP id gm4-20020a056214268400b0067f2d9b2753mr381126qvb.22.1704358988937; Thu, 04 Jan 2024 01:03:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704358988; cv=pass; d=google.com; s=arc-20160816; b=yY+gu0dibsIYWHWSFSajdk98Sfb/0nLRD/Q0tqmgOVxwIKy3uXsOEGVrlGwV/OQzqz YQaR9lcrHz/LTqcbP1snTvFcAo1aA6ItMHhVywCklHSK0e6L1EaiO/AHxOvB3tsdG2+Z 10V8FXIEnBGzA3jJFfcrJhz4NiUt1F+S/1rpHo0LiqsaBNG7PVHuT/9GYzmBnO1clEuW ZOVR83ubtgBLjWlxj/EAQbFYDOw64epy+bcYR4rHym6VNcR9UfMIpm49fuQ5tlYlr4CU j7UiKJTHAJcY1UbJqKle4KREMIhaFfFV/dckCXl+EHvO/gV1D7XacJ9NbeEYup0Xi0TJ Dp9w== 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=LDH7A2fN3vWL+St/Hp7Jt4zOaor6aojRfne9ByFpRj0=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=nZQI9fGKp7pO2LglmtcZp8r0nMtv6LCuqLWRcW0VVEE+OD+u5AAkD8utEwvJwMV2fm UBEYJ/TVK2Og8VbbmEHjkxWTKHhGnx7cBuEV2aQVyeKU17riVZX7ujl4pOrXbpp/rj+2 VvqI/rvrLj/65je9wmgkQgUoQdhNv6jTJP+BdYYmmR0IpeNywtSu0+9vBkhKQPJTAQ9H zFex1s3HTsvFkP1A9nUIi8juy0lk7PGc1criRbk0o0UULYaR43dkVaoIz5QDzu2hvRd7 vyRMOShGprcpzuFLsdXC5v6rzGRCc94sngcC8ZXnJ94avXSumxZFQWzkU41qnXCkHwa2 yNMQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=O8rKAryj; 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 c7-20020a0ce147000000b0067f623d7750si29251006qvl.468.2024.01.04.01.03.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 01:03:08 -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=O8rKAryj; 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 993BF3857C64 for ; Thu, 4 Jan 2024 09:03:08 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id EF2093858C53 for ; Thu, 4 Jan 2024 09:00:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF2093858C53 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 EF2093858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704358831; cv=none; b=aBtGff5KepyEQ+PUifzzfUMxoE/Kw9bfPW4gDz7lVlGD/6CpbP2AvmU9yCvFEABg8Q67ryXQalZEYEWkmb4t7PDDs3RN7aQoOdZM1MLaCItrSO+m4Cf6NYEHKOMyE/iXb1x4/P3bPOwNx6Ek2Fe2jY/0MjKLCJt4T3Whp6cra5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704358831; c=relaxed/simple; bh=8qR1uwyrYienSnHE46lhfvxDNmRvI6OtDtP9TV/3oJ4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=jsJ1nXd9njl4qghKcv14xuJKzOH40eqEUCzD9rFDgv4TgBCCCuE3LjalwrTc7irZUbzKdAWOsag1tpPaoY061GnVDEV/YSi+jTnWD1qqdUX1+ISZCpTIniVzjsH765WXIbfmP9HZpx6IGvNmUsC/EHjTuq4iBGyRToYDx1V2Zso= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704358824; 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=LDH7A2fN3vWL+St/Hp7Jt4zOaor6aojRfne9ByFpRj0=; b=O8rKAryjY/t7pXt0hOSOYXOcxKPUpe9n+c9ApS3yed5+YXmjKjELDzrHkUHzfL4UTZXJ5a mlCKZnmPuhtqOMnhg9ocl0k2ySF+L+cb8KlnfgquNoREDUwPJ6nDYguwZPKjP2zCpdBQS7 xALbymHWUA3EDaSXoHSkm+pkXNGChfM= 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-654-IJ7ZJajCPqeazEyg3ktz2w-1; Thu, 04 Jan 2024 04:00:22 -0500 X-MC-Unique: IJ7ZJajCPqeazEyg3ktz2w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 937E9803915; Thu, 4 Jan 2024 09:00:22 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5821C2026D66; Thu, 4 Jan 2024 09:00:22 +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 40490JRn3945041 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 4 Jan 2024 10:00:20 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40490JFp3945040; Thu, 4 Jan 2024 10:00:19 +0100 Date: Thu, 4 Jan 2024 10:00:18 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix up lowering of huge _BitInt 0 PHI args [PR113120] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, 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: 1787149931516461840 X-GMAIL-MSGID: 1787149931516461840 Hi! The PHI argument expansion of INTEGER_CSTs where bitint_min_cst_precision returns significantly smaller precision than the PHI result precision is optimized by loading the much smaller constant (if any) from memory and then either setting the remaining limbs to {} or calling memset with -1. The case where no constant is loaded (i.e. c == NULL) is when the INTEGER_CST is 0 or all_ones - in that case we can just set all the limbs to {} or call memset with -1 on everything. While for the all ones extension case that is what the code was already doing, I missed one spot in the zero extension case, where constricting the offset of the MEM_REF lhs of the = {} store it was using unconditionally the byte size of c, which obviously doesn't work if c is NULL. In that case we want to use zero offset. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-04 Jakub Jelinek PR tree-optimization/113120 * gimple-lower-bitint.cc (gimple_lower_bitint): Fix handling of very large _BitInt zero INTEGER_CST PHI argument. * gcc.dg/bitint-62.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-01-03 11:51:27.000000000 +0100 +++ gcc/gimple-lower-bitint.cc 2024-01-03 13:53:30.699328045 +0100 @@ -6582,8 +6582,12 @@ gimple_lower_bitint (void) = build_array_type_nelts (large_huge.m_limb_type, nelts); tree ptype = build_pointer_type (TREE_TYPE (v1)); - tree off = fold_convert (ptype, - TYPE_SIZE_UNIT (TREE_TYPE (c))); + tree off; + if (c) + off = fold_convert (ptype, + TYPE_SIZE_UNIT (TREE_TYPE (c))); + else + off = build_zero_cst (ptype); tree vd = build2 (MEM_REF, vtype, build_fold_addr_expr (v1), off); g = gimple_build_assign (vd, build_zero_cst (vtype)); --- gcc/testsuite/gcc.dg/bitint-62.c.jj 2024-01-03 14:11:22.332301884 +0100 +++ gcc/testsuite/gcc.dg/bitint-62.c 2024-01-03 14:10:58.219640178 +0100 @@ -0,0 +1,32 @@ +/* PR tree-optimization/113120 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +_BitInt(8) a; +_BitInt(55) b; + +#if __BITINT_MAXWIDTH__ >= 401 +static __attribute__((noinline, noclone)) void +foo (unsigned _BitInt(1) c, _BitInt(401) d) +{ + c /= d << b; + a = c; +} + +void +bar (void) +{ + foo (1, 4); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 6928 +_BitInt(6928) +baz (int x, _BitInt(6928) y) +{ + if (x) + return y; + else + return 0; +} +#endif