From patchwork Wed Oct 5 13:49:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp611161wrs; Wed, 5 Oct 2022 06:50:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM68s9TRE7obAV+UdhiJTsUySMNA0ll7lZUKSPC6bGEkv8DRx8Gx+hjuIInen/nHg9vNbuvu X-Received: by 2002:a17:907:7638:b0:78b:a9f0:add7 with SMTP id jy24-20020a170907763800b0078ba9f0add7mr11894522ejc.117.1664977832511; Wed, 05 Oct 2022 06:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664977832; cv=none; d=google.com; s=arc-20160816; b=nLclc7M3APCGa7QYTLwCtspEE6rjCz2+ulciz2CYTMbO4c2ndwc4DQHnvXtGP2DxdM 0kPi0acQnn79sn7t9chGJLolQSzciDFCnkSCANRjlfDt2/oBm3behtP1TRU+fDpb8GQ1 Ok0t+0qZUjDlt1lUowL3Bc/xwxEu1xvFXmwloS31knEiebyEA0yII8UbESjAUe4Axcx8 DrGsPb4g133/3QKzl47wFk1axxTq9gTefbFFVfVwvzKroDSYtXkzCHdmo4kGlDjgNp8M XcQVTsx6SLY1FtrNMGz+b5FqSWXX3TpYnANYym32Fbi5y4ypFXI5fG1jESIFzCwEMXix uBmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rfFJLi9//ugR/5jSwXbOq89NK0n82P4xwIoW8YUsBgI=; b=cpfoeq7qvIinrsrK4jWjNBxxjK/1CdBI1kfvT3oFeFtWE9shdaqk7EixBi0aWSZbDZ fqWZ5lVG4stt7Xiksk3S2VutUmiUbea4MFprHSzlAmWZ+6qmSOJetbCOsPNg5wPk2dUb zutEBQdzGOcy8Vivdua6TIqkjwEvkhp7dOetqtTqLvoPcpzPHCgU2SoswyuWSabYDszW CFT0Y8yJhBRsmhbwNJTM9iIkhApBfW+cY1l8jj2rn3151rbMzEnp2s9Qcb4/5+Pv9JlI EFJ6hCQIIgyE8bihABdoIzYZEPYctVsYbNpyv6JJnbZu+j+l/sGpsU9wcZ22U7lRhldW /iXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LbnS2JjC; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hw8-20020a170907a0c800b0078a9b8764besi9904845ejc.951.2022.10.05.06.50.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 06:50:32 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=LbnS2JjC; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E1DA3857379 for ; Wed, 5 Oct 2022 13:50:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E1DA3857379 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664977823; bh=rfFJLi9//ugR/5jSwXbOq89NK0n82P4xwIoW8YUsBgI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LbnS2JjCmdpa3ZJNIZpGndoxw8I7vu4QNZG43bOM9gH11STCL3sIhV+/t4PR59JFK /HAA6q5lbw355YA7l7p/9Ojf0daBBhjKDhJvOt7796hIGJkXlpcyaAVoiMfA3Ihr7X TbILa/qoehol3vZUDeQFKQeboNza0rhNqbI2mhNg= 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 A77633858297 for ; Wed, 5 Oct 2022 13:49:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A77633858297 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-578-pS-YL5UZMgWYvngjmdNCZg-1; Wed, 05 Oct 2022 09:49:39 -0400 X-MC-Unique: pS-YL5UZMgWYvngjmdNCZg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1904686EB54 for ; Wed, 5 Oct 2022 13:49:39 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8020140EBF5; Wed, 5 Oct 2022 13:49:38 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 295DnaU81584277 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 5 Oct 2022 15:49:36 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 295DnamB1584276; Wed, 5 Oct 2022 15:49:36 +0200 To: GCC patches Subject: [COMMITTED] range-op: Keep nonzero mask up to date with truncating casts. Date: Wed, 5 Oct 2022 15:49:32 +0200 Message-Id: <20221005134932.1584257-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745855795737959755?= X-GMAIL-MSGID: =?utf-8?q?1745855795737959755?= gcc/ChangeLog: * range-op.cc (operator_cast::fold_range): Handle truncating casts for nonzero masks. --- gcc/range-op.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 6fa27a8904e..df0735cb42a 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -2516,13 +2516,17 @@ operator_cast::fold_range (irange &r, tree type ATTRIBUTE_UNUSED, return true; } - // Pass nonzero mask through the cast. - if (!truncating_cast_p (inner, outer)) - { - wide_int nz = inner.get_nonzero_bits (); - nz = wide_int::from (nz, TYPE_PRECISION (type), TYPE_SIGN (inner.type ())); - r.set_nonzero_bits (nz); - } + // Update the nonzero mask. Truncating casts are problematic unless + // the conversion fits in the resulting outer type. + wide_int nz = inner.get_nonzero_bits (); + if (truncating_cast_p (inner, outer) + && wi::rshift (nz, wi::uhwi (TYPE_PRECISION (outer.type ()), + TYPE_PRECISION (inner.type ())), + TYPE_SIGN (inner.type ())) != 0) + return true; + nz = wide_int::from (nz, TYPE_PRECISION (type), TYPE_SIGN (inner.type ())); + r.set_nonzero_bits (nz); + return true; }