From patchwork Thu Dec 7 07:49:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 174981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4615850vqy; Wed, 6 Dec 2023 23:50:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCFTPXwcDOdyCQjpL/pHUtSQNZnN7MoBm60l6H6gtbV0Dzs0GG97v5/ZWz86rsntwuHpPz X-Received: by 2002:a37:c246:0:b0:77e:fba3:4f41 with SMTP id j6-20020a37c246000000b0077efba34f41mr870136qkm.151.1701935429021; Wed, 06 Dec 2023 23:50:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701935429; cv=pass; d=google.com; s=arc-20160816; b=YS0RxQhs6EhBAZniJzqJVxLE7Sb2Fz4wQBWSN7jXz7UdxvA7V8eK0lpVSUkmBW373q n91NtnQRp3FagR8GOVaYWX5D9R9eRoYqinRcyToCizX32tMpVpNeyR4x3zTlg221Bqj9 gIf/66e+bT0XYKoG/LS6yiQ2Ma1tYKpAUW1bhMkDRQxwfgqQgT8NjGtlxTQcEddM/WPH ku3OF7fW2eLgpUcSQ2i+CeBUz+h8jRoruJgKjAjvp0pchlvYBdlMfuyOrMEvjIGwTKbj gHNWqjIu5Nf779RfBE7qqGQ3rHn6o1z9CUmX/1X/o8aWIsuj6+4WP0fZ6bbIFlg1E/x2 Vmsg== 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=L2kulkJRJymeBL9UokSD3DUk6IG5BPmc+tjjrGN9n0o=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=S67LJl/p3YRS0343LXIc0g6SrbK+deyU5IuhqXHsDrEri7n41oldFog6oKMSaJF1P4 aQGyE/qjDYpkpIgW/cKnAYqlcB1Zv7jecOFv53b7EEmTwhr0XQl5j7djMvS3xJtaLf+M EO/ilnUHOCjOvC4hMEIKbdJG9ZP4wPGRM9MVifQpX6PiKLZMkeSYM/mckNT8A3hXDEmc AFwkm+UAxOIgHHxTIT8/5SGzoSJpZ8W9KkaXKW5kcN8kVG5u3WK9WCb9JKVc60cszsPT F52fa9J66ZbVtJdY80BwzPHUdxJVfQeMKvmMbXmWWluSVR0gBDUYBaJ60g18tumT1uai XIMg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zk4In65d; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id y15-20020a05620a44cf00b0077d6f870484si742438qkp.700.2023.12.06.23.50.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 23:50:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zk4In65d; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 C7B18385C6FC for ; Thu, 7 Dec 2023 07:50:28 +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 5852A385DC11 for ; Thu, 7 Dec 2023 07:50:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5852A385DC11 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 5852A385DC11 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=1701935407; cv=none; b=nZdofhY9EVvP6Sx1KupjklONGBqe+4/zUxVLlGtcyZ/wJYJiGXaSGOYT9nWGkCngLJ2pLuCChy+Ln0LbpLXfuHnsSFq0SailYvNXqN/uNYd9yBRWHZJEv6vqr9rI1FzWz84NvNiDMawtVU95Jz7ZKK4WNh4Vwqk7+bhyEz7kzRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701935407; c=relaxed/simple; bh=y14uGC9TPBRX3KDPNYOAA0ECua8hskn7xdmkA7g3K+w=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=UMH7rg3VkQmeU1jl5ek7LQ3636tC8NZghSctem+hcWGx38QM9iILLsN3WwtK2qOj9AtqDiTQFDui4J1wRiO4N3USBrSykFLloX8NiW+rmssBnnUWiDPlp4htv5fxe8QNz1fLKWIDXv1QE3mFiQbmq4Pk2riXYtmylqZbY+EmXIk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701935406; 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=L2kulkJRJymeBL9UokSD3DUk6IG5BPmc+tjjrGN9n0o=; b=Zk4In65d+fw67IcKg0oMWlSl6Hbugev+ktZs6/wjtvBT9e+SOF3JaQuqUI1gSUmuUE8Oa0 sKxXoEPfziyWf2k7dl2lfhKjy4w75iYCRy8pF8DYvaZAb938bTv+nmlqJvTvQRM3xsXGk5 31W9l1z74IZmM5yTkpm1MF3/OmGSSm0= 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-115-4Un7ih9EMf-IAkWP25Umsw-1; Thu, 07 Dec 2023 02:50:02 -0500 X-MC-Unique: 4Un7ih9EMf-IAkWP25Umsw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 1C0B8108BCA3; Thu, 7 Dec 2023 07:50:02 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D40D21C060AF; Thu, 7 Dec 2023 07:50:01 +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 3B77nxfl161422 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 7 Dec 2023 08:49:59 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B77nwvA161417; Thu, 7 Dec 2023 08:49:58 +0100 Date: Thu, 7 Dec 2023 08:49:58 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-ssa-dce: Fix up maybe_optimize_arith_overflow for BITINT_TYPE [PR112880] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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, 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: 1784608644093871618 X-GMAIL-MSGID: 1784608644093871618 Hi! The following testcase ICEs because maybe_optimize_arith_overflow uses build_nonstandard_integer_type, which is inappropriate if type is large BITINT_TYPE. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-07 Jakub Jelinek PR tree-optimization/112880 * tree-ssa-dce.cc (maybe_optimize_arith_overflow): Use unsigned_type_for instead of conditionally calling build_nonstandard_integer_type. * gcc.dg/bitint-49.c: New test. Jakub --- gcc/tree-ssa-dce.cc.jj 2023-12-05 16:14:36.833248092 +0100 +++ gcc/tree-ssa-dce.cc 2023-12-06 17:16:42.740873447 +0100 @@ -1241,9 +1241,7 @@ maybe_optimize_arith_overflow (gimple_st tree arg1 = gimple_call_arg (stmt, 1); location_t loc = gimple_location (stmt); tree type = TREE_TYPE (TREE_TYPE (lhs)); - tree utype = type; - if (!TYPE_UNSIGNED (type)) - utype = build_nonstandard_integer_type (TYPE_PRECISION (type), 1); + tree utype = unsigned_type_for (type); tree result = fold_build2_loc (loc, subcode, utype, fold_convert_loc (loc, utype, arg0), fold_convert_loc (loc, utype, arg1)); --- gcc/testsuite/gcc.dg/bitint-49.c.jj 2023-12-06 17:15:30.461888327 +0100 +++ gcc/testsuite/gcc.dg/bitint-49.c 2023-12-06 17:15:01.669292609 +0100 @@ -0,0 +1,37 @@ +/* PR tree-optimization/112880 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +#if __BITINT_MAXWIDTH__ >= 1024 +_BitInt(1024) a, b, c, d, e, f; + +void +foo (void) +{ + __builtin_add_overflow (a, b, &a); + __builtin_sub_overflow (c, d, &c); + __builtin_mul_overflow (e, f, &e); +} +#endif + +#if __BITINT_MAXWIDTH__ >= 512 +_BitInt(512) g, h, i, j, k, l; + +void +bar (void) +{ + __builtin_add_overflow (g, h, &g); + __builtin_sub_overflow (i, j, &i); + __builtin_mul_overflow (k, l, &k); +} +#endif + +_BitInt(32) m, n, o, p, q, r; + +void +baz (void) +{ + __builtin_add_overflow (m, n, &m); + __builtin_sub_overflow (o, p, &o); + __builtin_mul_overflow (q, r, &q); +}