From patchwork Mon Oct 3 11:08:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1652 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp893978wrs; Mon, 3 Oct 2022 04:10:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nYFwlcarMI/u7m7DeTivvMgrkzAvdP8Y6HgnIIbOp6UQyYSR3LoZhVmXlXv5+fwg7VHKl X-Received: by 2002:a05:6402:90c:b0:457:b5ce:5f18 with SMTP id g12-20020a056402090c00b00457b5ce5f18mr18748836edz.309.1664795418805; Mon, 03 Oct 2022 04:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664795418; cv=none; d=google.com; s=arc-20160816; b=IvN4sVsOv9VnX6SYFNRsSlQCI3kYm51AnhMm/Nj56eiMaM2uxkJCHDtROwXvfJMJgW idFWKdnkWRfJDtfxs9Wq5YU4l8lUtyaZdx8dL/UUb+Xg/u7qbEmCFJYxpze26Wbi58ac TCoahhGLvBeIv5H3PhZ+zOYTNeSBxYnUTUnVKuXtH8Ke5wjLlSHUpQQGgYfQDA+xh7T9 zpinA8IR4OwhZxOi5GVk5RxG3NkHrreVFR0hhd/vzeZvbT90KwaI4wGaEmvH993srD8+ 9zFYTdKQgMrqEog44adveeK6u1Q4IYi4vagFgAFtbKZYCwdm3B7DgPhQ+ENg4SDywNSA D7JA== 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:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=BQNseqyJNZpmYBfsriDBVSVp3BwdLpbqq6HO2l3oOug=; b=nWP1nicsbQ8cF1CD9WY1RIl3XTb23dM3kTSXeIe74G1EDIbURXe9laNdM+WFKq+ZpA gtT02e5A2HK7aVGDUJeKHRoPCbeXytrB5P2Sr96qcHoXs530XnUuw6iM1/8DIRqNT21n sp2c4JzgGYQW98+6aj9SQyKLiQHbrPeEOsNk7AVjIbjqgAzzSaJQpVbRV9uthm8DCWHp yC/RhQ+h2oZ+5mk3FaX2mto8lHgx9a3GQKWHJh2EItiD/eDcLjyZaNeToy/YeIkzqejx qbkbEbe2h1P+1GPmLGl2jX/+Hq5vsYMRFhwXikYqpUvvLoWHuzqYhDtfk/H6YOYDsR3w azxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=doI9FPtW; 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 z12-20020a50cd0c000000b00451e0d930dfsi7616972edi.497.2022.10.03.04.10.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 04:10:18 -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=doI9FPtW; 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 61FDF385841F for ; Mon, 3 Oct 2022 11:10:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61FDF385841F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664795400; bh=BQNseqyJNZpmYBfsriDBVSVp3BwdLpbqq6HO2l3oOug=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=doI9FPtW0CR8H/zjuEXagSxu4NJK+pVVNY/OJ+Fd8J12b33iZKa9BFdcivDqb/eqU LaZ77LcmqhM0QzxklEJvo6en3Sbzq1NkGh4YvS5vGOcoodf0lJDRh9gjmopNHMsOzU 8/QuBjrD4pgmYyDbULaCHqI0el8fORtd9VodZX6o= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 7ECBB3858D38 for ; Mon, 3 Oct 2022 11:08:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7ECBB3858D38 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-103-eFkbtqXqP6-BjzulsicgPQ-1; Mon, 03 Oct 2022 07:08:21 -0400 X-MC-Unique: eFkbtqXqP6-BjzulsicgPQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCD091019C8F for ; Mon, 3 Oct 2022 11:08:20 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D23F492B04; Mon, 3 Oct 2022 11:08:20 +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 293B8JTF1076007 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 3 Oct 2022 13:08:19 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 293B8JmS1076006; Mon, 3 Oct 2022 13:08:19 +0200 To: GCC patches Subject: [COMMITTED] Do not pessimize range in set_nonzero_bits. Date: Mon, 3 Oct 2022 13:08:15 +0200 Message-Id: <20221003110815.1075975-4-aldyh@redhat.com> In-Reply-To: <20221003110815.1075975-1-aldyh@redhat.com> References: <20221003110815.1075975-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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_LOW, 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?1745664521045196517?= X-GMAIL-MSGID: =?utf-8?q?1745664521045196517?= Currently if we have a range of [0,0] and we set the nonzero bits to 1, the current code pessimizes the range to [0,1] because it assumes the range is [1,1] plus the possibility of 0. This fixes the oversight. gcc/ChangeLog: * value-range.cc (irange::set_nonzero_bits): Do not pessimize range. (range_tests_nonzero_bits): New test. --- gcc/value-range.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index e1066f4946e..6e196574de9 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -2934,6 +2934,14 @@ irange::set_nonzero_bits (const wide_int_ref &bits) // range immediately. if (wi::popcount (bits) == 1) { + // Make sure we don't pessimize the range. + tree tbits = wide_int_to_tree (type (), bits); + if (!contains_p (tbits)) + { + set_nonzero_bits (tbits); + return; + } + bool has_zero = contains_p (build_zero_cst (type ())); set (type (), bits, bits); if (has_zero) @@ -3628,6 +3636,11 @@ range_tests_nonzero_bits () r1.set_nonzero_bits (0xff); r0.union_ (r1); ASSERT_TRUE (r0.varying_p ()); + + // Test that setting a nonzero bit of 1 does not pessimize the range. + r0.set_zero (integer_type_node); + r0.set_nonzero_bits (1); + ASSERT_TRUE (r0.zero_p ()); } // Build an frange from string endpoints.