From patchwork Fri Dec 22 08:12:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 82743 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F8793858433 for ; Fri, 22 Dec 2023 08:12:49 +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 567A43858D3C for ; Fri, 22 Dec 2023 08:12:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 567A43858D3C 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 567A43858D3C 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=1703232752; cv=none; b=F/Th8nNAuEVvx+Ibz+gaXRrOREqQ3NptZKtd21sLIPBuIdbfC7DnUZNKBceJeMAItBYHDmC8GJiiCDGL3ptN1DpDkzI3tJHZ2tJLKfy7kYunOcRHYCEJS0Lt+RE1cAxmFGqHN5g6FbRj1miIVWVn1BxZRWROBR1FvVNzdDKjBeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703232752; c=relaxed/simple; bh=VZrNYZ8uAqpBA8glZFhW1hrlM9PpenGFjNrMFq3DnOg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Ig0NW4k0ExWmKSt7CNVcvpV7tZRC3jeWJDpjndImEpAOcGUPHpfOQS/evXRJAjY5RGvenrnXrAuKJwmY77SMTsHnpiTYrRVzCJy0ESsruUriOe5fQDnO6GxE4EpXUqzVIOp2oVh8VxI9XCKAcDb8tXo999mikgJT4LGDhOfOO1s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703232751; 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=zwq1/qcwLA6J+6pXa+fjx25+1HrvcPQCDzlQxeXwHGY=; b=VZIvrV0JYToRCqIFO28wzh0T6906MqbmsGPJoFEeA86pzQGdgvMwe/2KEHMt+x5gU+UnJS 7vCI6ssv6n5TtS/bTZGhe8Mkk0JtLMx03yd0RJdrgjw70V5vZbevmDCbSJS19XpD2VGNfs r8OSZD/5IpHfuxw2gRQM+ZhfVvRE6IY= 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-614-3HZAFL5ANFCIocj1-EB8tw-1; Fri, 22 Dec 2023 03:12:27 -0500 X-MC-Unique: 3HZAFL5ANFCIocj1-EB8tw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 10ACB85A589; Fri, 22 Dec 2023 08:12:27 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C93E340C6EB9; Fri, 22 Dec 2023 08:12:26 +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 3BM8CO95241222 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Dec 2023 09:12:24 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3BM8CNv5241221; Fri, 22 Dec 2023 09:12:23 +0100 Date: Fri, 22 Dec 2023 09:12:23 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix handle_cast ICE [PR113102] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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_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+patchwork=sourceware.org@gcc.gnu.org Hi! My recent change to use m_data[save_data_cnt] instead of m_data[save_data_cnt + 1] when inside of a loop (m_bb is non-NULL) broke the following testcase. When we create a PHI node on the loop using prepare_data_in_out, both m_data[save_data_cnt{, + 1}] are computed and the fix was right, but there are also cases when we in a loop (m_bb non-NULL) emit a nested cast with too few limbs and then just use constant indexes for all accesses - in that case only m_data[save_data_cnt + 1] is initialized and m_data[save_data_cnt] is NULL. In those cases, we want to use the former. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-22 Jakub Jelinek PR tree-optimization/113102 * gimple-lower-bitint.cc (bitint_large_huge::handle_cast): Only use m_data[save_data_cnt] if it is non-NULL. * gcc.dg/bitint-58.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-12-21 11:13:32.000000000 +0100 +++ gcc/gimple-lower-bitint.cc 2023-12-21 13:28:56.953120687 +0100 @@ -1491,7 +1491,7 @@ bitint_large_huge::handle_cast (tree lhs m_data_cnt = tree_to_uhwi (m_data[save_data_cnt + 2]); if (TYPE_UNSIGNED (rhs_type)) t = build_zero_cst (m_limb_type); - else if (m_bb) + else if (m_bb && m_data[save_data_cnt]) t = m_data[save_data_cnt]; else t = m_data[save_data_cnt + 1]; --- gcc/testsuite/gcc.dg/bitint-58.c.jj 2023-12-21 13:33:25.882383838 +0100 +++ gcc/testsuite/gcc.dg/bitint-58.c 2023-12-21 13:32:54.408821172 +0100 @@ -0,0 +1,31 @@ +/* PR tree-optimization/113102 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +_BitInt(3) a; +#if __BITINT_MAXWIDTH__ >= 4097 +_BitInt(8) b; +_BitInt(495) c; +_BitInt(513) d; +_BitInt(1085) e; +_BitInt(4096) f; + +void +foo (void) +{ + a -= (_BitInt(4097)) d >> b; +} + +void +bar (void) +{ + __builtin_sub_overflow ((_BitInt(767)) c >> e, 0, &a); +} + +void +baz (void) +{ + _BitInt(768) x = (_BitInt(257))f; + b /= x >> 0 / 0; /* { dg-warning "division by zero" } */ +} +#endif