From patchwork Mon Sep 27 10:25:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1533254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=mr5LGkLj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HHzMJ4JrTz9tkJ for ; Mon, 27 Sep 2021 20:26:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1562E3858436 for ; Mon, 27 Sep 2021 10:26:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1562E3858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632738393; bh=9xZ+Ht2Fe/MGW5j6JzZF8+yzArZ3yzR+PkvJQaVpVrk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mr5LGkLjIiazmR6p29OxiYTWy7QlMnJy4RMFyiqoYAZhPMIA71mLxrKYE0x2Xplb8 is5X8Y/pQFWsg3EnnXbuEwIm/ctiRMqh1ABADAygiU06e42DHATcg2xNOLwGMwgOpj DBRGYXVgYrROjQzSnIjk3Wn3N0KoSguCjFjw3/fM= 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 ESMTP id 4C5F53858C3A for ; Mon, 27 Sep 2021 10:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C5F53858C3A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-uOtUvGvjO3u_4eo5IO9nIQ-1; Mon, 27 Sep 2021 06:26:11 -0400 X-MC-Unique: uOtUvGvjO3u_4eo5IO9nIQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E10A21006AA7 for ; Mon, 27 Sep 2021 10:26:10 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.193.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79F475C23A; Mon, 27 Sep 2021 10:26:10 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 18RAQ7uO748070 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 27 Sep 2021 12:26:08 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 18RAQ7JT748069; Mon, 27 Sep 2021 12:26:07 +0200 To: GCC patches Subject: [COMMITTED] Use on-demand ranges in ssa_name_has_boolean_range before querying nonzero bits. Date: Mon, 27 Sep 2021 12:25:23 +0200 Message-Id: <20210927102522.747987-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The function ssa_name_has_boolean_range looks at the nonzero bits stored in SSA_NAME_RANGE_INFO. These are global in nature and are the result of a previous evrp/VRP run (technically other passes can also set them). However, we can do better if we use get_range_query. Doing so will use a ranger if enabled in a pass, or global ranges otherwise. The call to get_nonzero_bits remains, as there are passes that will set them independently of the global range info. Tested on x86-64 Linux with a regstrap as well as in a DOM environment using an on-demand ranger instead of evrp. Committed to trunk. gcc/ChangeLog: * tree-ssanames.c (ssa_name_has_boolean_range): Use get_range_query. --- gcc/tree-ssanames.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c index 2165ad71cf3..f427c5a789b 100644 --- a/gcc/tree-ssanames.c +++ b/gcc/tree-ssanames.c @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa.h" #include "cfgloop.h" #include "tree-scalar-evolution.h" +#include "value-query.h" /* Rewriting a function into SSA form can create a huge number of SSA_NAMEs, many of which may be thrown away shortly after their creation if jumps @@ -484,7 +485,7 @@ get_nonzero_bits (const_tree name) This can be because it is a boolean type, any unsigned integral type with a single bit of precision, or has known range of [0..1] - via VRP analysis. */ + via range analysis. */ bool ssa_name_has_boolean_range (tree op) @@ -502,12 +503,20 @@ ssa_name_has_boolean_range (tree op) return true; /* An integral type with more precision, but the object - only takes on values [0..1] as determined by VRP + only takes on values [0..1] as determined by range analysis. */ if (INTEGRAL_TYPE_P (TREE_TYPE (op)) - && (TYPE_PRECISION (TREE_TYPE (op)) > 1) - && wi::eq_p (get_nonzero_bits (op), 1)) - return true; + && (TYPE_PRECISION (TREE_TYPE (op)) > 1)) + { + int_range<2> onezero (build_zero_cst (TREE_TYPE (op)), + build_one_cst (TREE_TYPE (op))); + int_range<2> r; + if (get_range_query (cfun)->range_of_expr (r, op) && r == onezero) + return true; + + if (wi::eq_p (get_nonzero_bits (op), 1)) + return true; + } return false; }