From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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); +} Jakub