From patchwork Tue Jul 26 11:06:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp2186291pxt; Tue, 26 Jul 2022 04:07:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1veomnQRriB6wLoQBEYVNDaJElQMfq0y3w5Kn+vSmU94VpJAur0JbGfqzGwRVEmybC3HJ+X X-Received: by 2002:a05:6402:28ca:b0:43b:5235:f325 with SMTP id ef10-20020a05640228ca00b0043b5235f325mr17412820edb.320.1658833656547; Tue, 26 Jul 2022 04:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658833656; cv=none; d=google.com; s=arc-20160816; b=rZn4iLlT6Zzjt8fjCoHTAw9kSLWRWVflLhKXqJS10YniOFHumnEfjZxaBKA3Cwrc5/ ToYSEibfBXeNAF+O0dAttx7FSNB/6vnI+TLfuMGS0ORa6IFON8M9kMkoI9hTa6olvjmk 0NUcrssCwf7t0SDYd6LzN1XmFCxk9xEy9QvsqkrY8uuzrxVBHLh69HrtjapyO/Nu4Kwx OgHDaGvj/sMBTeHSe3sNnv4gXc4C01/8B4OGZO0uuji5i5ve/GfJJzSoLEM4olVkajS+ IKaXGrRECaIY/kV3CxJJEw76nq9crjFpIdmyn6J+tXww5diAdzVy3D2OtUWrdb1GlJOq DyxA== 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=xbLprui/woOsAwdb+VkalLzXU6DCGjURmLaqFvowcv0=; b=vmbd4js8UHvoNlAvUqw3iCewtPQdG8mkRHJ1a8XmnRTPgyDskmkembg317S5jBEbK2 O7+o2poonFJbGpjnSJLXYskp1+NLnOEBPuw0K41cNyAy6RdoPAMifwwJJzS2afZmM9aB U3rNar1S740VRI3cSiDjJXDyLa29Qou9zfZnlJ6wkK7eGpwzEI47WAGhY82zQUeK37bu HVUWiGHwjzLpg/MgLq6PJWu7tchXiHzgyFWnA3zYyMVQd3dtKTQP85TIYex03q3xNWf+ U8jSkrrD0chaPh669WB/zyb1SZ5uTUZU1apRPYch02ETqvzsEbkruxtitOsGT7zyWrs9 ZazQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FIXxmEDe; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id du22-20020a17090772d600b00726b8363630si16410516ejc.923.2022.07.26.04.07.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 04:07:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FIXxmEDe; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 6D84B385700A for ; Tue, 26 Jul 2022 11:07:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D84B385700A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658833649; bh=xbLprui/woOsAwdb+VkalLzXU6DCGjURmLaqFvowcv0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FIXxmEDenPuvLMVbVEBMqmuQvofMfDMI4mJ/u95fEyDyHVb5rhRhf8XAkwTSZGrLu Xg7sEBV/z3XxFO8Ya0a6b9wTc3QB2qStCcx/kcO4SKZcNDlIg4A3ir1OTKa5i7OAGf kTckw4+xpPNYupEvpybRq9fYaOnWZ+1eeVmmV31Y= 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 A19093858005 for ; Tue, 26 Jul 2022 11:06:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A19093858005 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-148-7C5f85G3NgK4W6WPqPXCdw-1; Tue, 26 Jul 2022 07:06:44 -0400 X-MC-Unique: 7C5f85G3NgK4W6WPqPXCdw-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 E8012804191 for ; Tue, 26 Jul 2022 11:06:43 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.107]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E02E492C3B; Tue, 26 Jul 2022 11:06:43 +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 26QB6fA32244343 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 26 Jul 2022 13:06:41 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 26QB6eKd2244342; Tue, 26 Jul 2022 13:06:40 +0200 To: GCC patches Subject: [COMMITTED] [106444] Handle non constant ranges in irange pretty printer. Date: Tue, 26 Jul 2022 13:06:11 +0200 Message-Id: <20220726110610.2244312-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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?1739413160127911630?= X-GMAIL-MSGID: =?utf-8?q?1739413160127911630?= Technically iranges only exist in constant form, but we allow symbolic ones before arriving in the ranger, so legacy VRP can work. This fixes the ICE when attempting to print symbolic iranges in the pretty printer. For consistency's sake, I have made sure irange::get_nonzero_bits does not similarly ICE on a symbolic range, even though no one should be querying nonzero bits on such a range. This should all melt away when legacy disappears, because all these methods are slated for removal (min, max, kind, symbolic_p, constant_p, etc). Finally, Richi suggested using pp_wide_int in the pretty printer instead of going through trees. I've adapted a test, since dump_generic_node seems to work slightly different. PR tree-optimization/106444 gcc/ChangeLog: * value-range-pretty-print.cc (vrange_printer::visit): Handle legacy ranges. (vrange_printer::print_irange_bound): Work on wide_int's. * value-range-pretty-print. (print_irange_bound): Same. * value-range.cc (irange::get_nonzero_bits): Handle legacy ranges. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/evrp4.c: Adjust. --- gcc/testsuite/gcc.dg/tree-ssa/evrp4.c | 2 +- gcc/value-range-pretty-print.cc | 33 ++++++++++++++++----------- gcc/value-range-pretty-print.h | 2 +- gcc/value-range.cc | 8 +++++++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/evrp4.c b/gcc/testsuite/gcc.dg/tree-ssa/evrp4.c index e3f4531b16c..895109fdadd 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/evrp4.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/evrp4.c @@ -17,4 +17,4 @@ int bar (struct st *s) foo (&s->a); } -/* { dg-final { scan-tree-dump "\\\[1B, \\+INF\\\]" "evrp" } } */ +/* { dg-final { scan-tree-dump "\\\[1, \\+INF\\\]" "evrp" } } */ diff --git a/gcc/value-range-pretty-print.cc b/gcc/value-range-pretty-print.cc index 485612fe67c..cbf50d3d854 100644 --- a/gcc/value-range-pretty-print.cc +++ b/gcc/value-range-pretty-print.cc @@ -63,38 +63,45 @@ vrange_printer::visit (const irange &r) const pp_string (pp, "VARYING"); return; } - for (unsigned i = 0; i < r.num_pairs (); ++i) + // Handle legacy symbolics. + if (!r.constant_p ()) { - tree lb = wide_int_to_tree (r.type (), r.lower_bound (i)); - tree ub = wide_int_to_tree (r.type (), r.upper_bound (i)); + if (r.kind () == VR_ANTI_RANGE) + pp_character (pp, '~'); pp_character (pp, '['); - print_irange_bound (lb); + dump_generic_node (pp, r.min (), 0, TDF_NONE, false); pp_string (pp, ", "); - print_irange_bound (ub); + dump_generic_node (pp, r.max (), 0, TDF_NONE, false); + pp_character (pp, ']'); + print_irange_bitmasks (r); + return; + } + for (unsigned i = 0; i < r.num_pairs (); ++i) + { + pp_character (pp, '['); + print_irange_bound (r.lower_bound (i), r.type ()); + pp_string (pp, ", "); + print_irange_bound (r.upper_bound (i), r.type ()); pp_character (pp, ']'); } print_irange_bitmasks (r); } void -vrange_printer::print_irange_bound (tree bound) const +vrange_printer::print_irange_bound (const wide_int &bound, tree type) const { - tree type = TREE_TYPE (bound); wide_int type_min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type)); wide_int type_max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type) - && TREE_CODE (bound) == INTEGER_CST - && wi::to_wide (bound) == type_min + && bound == type_min && TYPE_PRECISION (type) != 1) pp_string (pp, "-INF"); - else if (TREE_CODE (bound) == INTEGER_CST - && wi::to_wide (bound) == type_max - && TYPE_PRECISION (type) != 1) + else if (bound == type_max && TYPE_PRECISION (type) != 1) pp_string (pp, "+INF"); else - dump_generic_node (pp, bound, 0, TDF_NONE, false); + pp_wide_int (pp, bound, TYPE_SIGN (type)); } void diff --git a/gcc/value-range-pretty-print.h b/gcc/value-range-pretty-print.h index c1c7c4244cc..ad06c93c044 100644 --- a/gcc/value-range-pretty-print.h +++ b/gcc/value-range-pretty-print.h @@ -29,7 +29,7 @@ public: void visit (const irange &) const override; void visit (const frange &) const override; private: - void print_irange_bound (tree bound) const; + void print_irange_bound (const wide_int &w, tree type) const; void print_irange_bitmasks (const irange &) const; void print_frange_prop (const char *str, const fp_prop &) const; diff --git a/gcc/value-range.cc b/gcc/value-range.cc index e49b06d1038..2923f4f5a0e 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -2593,6 +2593,14 @@ irange::get_nonzero_bits () const { gcc_checking_assert (!undefined_p ()); + // In case anyone in the legacy world queries us. + if (!constant_p ()) + { + if (m_nonzero_mask) + return wi::to_wide (m_nonzero_mask); + return wi::shwi (-1, TYPE_PRECISION (type ())); + } + // Calculate the nonzero bits inherent in the range. wide_int min = lower_bound (); wide_int max = upper_bound ();