From patchwork Fri Dec 1 08:05:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 81079 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 DF91B385B538 for ; Fri, 1 Dec 2023 08:06:04 +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 C9BDE3858C62 for ; Fri, 1 Dec 2023 08:05:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9BDE3858C62 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 C9BDE3858C62 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=1701417948; cv=none; b=h6Ilel4tUA8EQtJM1+8YfRIWo40OglfebUDFfvY9kI3lnzlYTENIJ2WrIX0tkxbmRTxt3/3VGHZflUA6Otsp75da60KBHxhezruhzzYG90EjXOzNCy5GwbGcxaKyf4zfz6iYlm+sQhqrJqt218Hlccn++0Llui0JjjTvyHYQFkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701417948; c=relaxed/simple; bh=p9clRaWWsLyONVbxmYpT7pA94jhY+rNKLYXbVIGx60E=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=U6U5OZWx1PQCCa3jfzxT4ke8Yu0Le1mNShKirwWxblJnafmYILdGzwNTqAE5a2yAGF/HtKfQ+B7cYurUcWw+UCoU6rXBIo/gCrKwoSitxMMIepycyhzHeoqOthG9UcsHDrZrWMdferrEdPQtirWvEQC8cs02nfetQ2kd2wGOKEA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701417945; 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=QLCG6mUwHx+wytX1HE9ck4V72/ayABpgx9CXxO68CEE=; b=NXr9T2J7rUDCNU84lp3wmyz4xty/rBYRnNeMTYrbrkbgfYi7nPw5GVBOu7HrhY0YoX8dqK oxHz+tpSbbJXFOg2jon9AbMt6dlnSefg1/0Jq2Cj1whWCQD+PKAgdL5x7NeV187n7/Jas5 YYrhmWQ2dgJ3zeUH0Dtp8B5Pp6lvLoQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-400-Yjfeb-88Ot2VKT8k4j7UZw-1; Fri, 01 Dec 2023 03:05:44 -0500 X-MC-Unique: Yjfeb-88Ot2VKT8k4j7UZw-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 E0DF23816B4D; Fri, 1 Dec 2023 08:05:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4D8A1C060AE; Fri, 1 Dec 2023 08:05:43 +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 3B185a5T540275 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 1 Dec 2023 09:05:36 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B185Zck540274; Fri, 1 Dec 2023 09:05:35 +0100 Date: Fri, 1 Dec 2023 09:05:35 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix up handle_operand_addr for 0 constants [PR112771] 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.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+patchwork=sourceware.org@gcc.gnu.org Hi! handle_operand_addr for INTEGER_CSTs uses wi::min_precision (UNSIGNED for non-negative constants, SIGNED for negative ones) and from that computes mp as minimum number of limbs which can represent that value, and in some cases creates a test BITINT_TYPE with that precision to categorize it and decide based on that what types to use on the constant emitted into memory. For the actual precisions (what will be passed to libgcc) it actually already uses MAX/MIN to adjust the corner cases: *prec = MAX (min_prec, 1); ... *prec = MIN ((int) -min_prec, -2); but for integer_zerop min_prec will be 0, mp = CEIL (min_prec, limb_prec) * limb_prec; will be also 0 and we ICE trying to build unsigned BITINT_TYPE with 0 precision. Fixed thusly by noting even 0 has to be encoded at least as one limb. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-01 Jakub Jelinek PR middle-end/112771 * gimple-lower-bitint.cc (bitint_large_huge::handle_operand_addr): Use mp = limb_prec if it is zero. * gcc.dg/bitint-44.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-11-30 17:24:59.828026693 +0100 +++ gcc/gimple-lower-bitint.cc 2023-11-30 17:42:07.172487347 +0100 @@ -2179,6 +2179,8 @@ bitint_large_huge::handle_operand_addr ( *prec = MIN ((int) -min_prec, -2); } mp = CEIL (min_prec, limb_prec) * limb_prec; + if (mp == 0) + mp = limb_prec; if (mp >= (unsigned) TYPE_PRECISION (TREE_TYPE (op))) type = TREE_TYPE (op); else --- gcc/testsuite/gcc.dg/bitint-44.c.jj 2023-11-30 17:45:02.421017172 +0100 +++ gcc/testsuite/gcc.dg/bitint-44.c 2023-11-30 17:39:51.968393081 +0100 @@ -0,0 +1,10 @@ +/* PR middle-end/112771 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-std=c23" } */ + +_BitInt(575) +foo (_BitInt(575) a) +{ + a /= 0; /* { dg-warning "division by zero" } */ + return a; +}