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: 172310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp955816vqy; Fri, 1 Dec 2023 00:06:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHE7ZjGIz2QGHjQ1Lhx0Zx2VNWkZw4i7jnPrp9OyrAmcij2UlZWxZCAbUbVuHrmAZ4YB0U2 X-Received: by 2002:a81:d549:0:b0:5c9:9097:6427 with SMTP id l9-20020a81d549000000b005c990976427mr23936979ywj.44.1701417973614; Fri, 01 Dec 2023 00:06:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701417973; cv=pass; d=google.com; s=arc-20160816; b=IlxPh5ZdPCFASveu/tlqAJ6+lzclnwuVYQ5MOP1e+OBwrDIWeZIBcWmyNJ/FHLE6E1 HB3bQ/eY8JTtLHKqTgZ1Tu3DVHd2ZmbnqHMg+D3sfMAo7Jt2MCI7uzsurewlEm7fcbUi uOz/SBzW0U9caPFyIiiauv47QPGOwm2RpQOsUkboRsbfUh8MGEPhYGbMeTlCZIg8d2O3 mzclcghRiu3lxj1jsmtY5FfQlLRXC+/Sodyg65J0Ox4ZO1a2ADjwQhNlJQeFXnEaeKyb k6rUSBYIQy0LCQ2YMJtBFMwK0nYL+JT4Qca8fCQnCIWmz/2WAPsMwsQHHkkEwP8Wjydx kwhQ== 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=QLCG6mUwHx+wytX1HE9ck4V72/ayABpgx9CXxO68CEE=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=vKV4egfrO81fhwyvVZ+CESIiVze/BmzGZrzgnqYgDxGHZfCCwtb2nyW6pQrzhI7rsJ +Wf52onauxudHwLGH0QbQStcUEYDqHq60H9sR4Cli0djhc/jIAqXKD221FUyEp5UQoMO 3X7M5Cym2wAtCpcPGcsdHwkFY/8ANMn0DR4Rs+srlzUtr4FA5YeZlEXemuK5aSTrAVwr E4v+xwkGSj5MZRfs/dhJVuJUkKmvzLUx83jVmMePj4spOmDLruvtN9wzqixkTYTn81A9 TX3c+ewkc3f877PBpvex1AdGbcG7d7sTZbOtI1VxELFgC1OBykXrHHa/D0cdAXpOwfTi BCGg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NXr9T2J7; 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 c14-20020ad4430e000000b0067a9ccea62dsi250633qvs.432.2023.12.01.00.06.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 00:06:13 -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=NXr9T2J7; 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 62D2B3857C4B for ; Fri, 1 Dec 2023 08:06:13 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784066053117626897 X-GMAIL-MSGID: 1784066053117626897 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; +}