From patchwork Fri Oct 1 12:43:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 45677 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE6753857C75 for ; Fri, 1 Oct 2021 12:44:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE6753857C75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633092292; bh=uiBGRrQiYs5KcH2lCPhTw8Vfi8ClKjCOCMNW6zb7N7U=; 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=X68hDbVS4h34neu3BoysMSnu1/lkyHvZhnmOkG7LHBbpm4yLmcXoadlzntGYfl1xz p0sqvUgZ/TioOIqaQVEY7Dq7fC4ArwMj4sSZt3jR6eEMpbdzavzHVwCBZqZHHfSDvW mmrpHS7yW6p+Y9W5EphvywdACMPzsYnx63voeHTY= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 8F4FC3857C7B for ; Fri, 1 Oct 2021 12:43:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8F4FC3857C7B 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-337-EcsWM4jSNUWfgVY7LVvmEQ-1; Fri, 01 Oct 2021 08:43:31 -0400 X-MC-Unique: EcsWM4jSNUWfgVY7LVvmEQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DBB25800053 for ; Fri, 1 Oct 2021 12:43:30 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.193.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A99E10023AE; Fri, 1 Oct 2021 12:43:23 +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 191ChLCb1458282 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 1 Oct 2021 14:43:21 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 191ChLmJ1458281; Fri, 1 Oct 2021 14:43:21 +0200 To: GCC patches Subject: [PATCH] Pass relations down to range_operator::op[12]_range. Date: Fri, 1 Oct 2021 14:43:06 +0200 Message-Id: <20211001124306.1458223-2-aldyh@redhat.com> In-Reply-To: <20211001124306.1458223-1-aldyh@redhat.com> References: <20211001124306.1458223-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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, RCVD_IN_MSPIKE_H2, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" It looks like we don't pass relations down to the op[12]_range operators. This is causing problems when implementing some relational magic for the shift operators. Andrew, this looks like an oversight. If so, how does this look? Tested on x86-64 Linux. gcc/ChangeLog: * gimple-range-gori.cc (gimple_range_calc_op1): Add relation argument. (gimple_range_calc_op2): Same. (gori_compute::compute_operand1_range): Pass relation to gimple_range_calc_op*. (gori_compute::compute_operand2_range): Same. --- gcc/gimple-range-gori.cc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 4a1ade7f921..c7cfb71d849 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -59,7 +59,8 @@ gimple_range_calc_op1 (irange &r, const gimple *stmt, const irange &lhs_range) bool gimple_range_calc_op1 (irange &r, const gimple *stmt, - const irange &lhs_range, const irange &op2_range) + const irange &lhs_range, const irange &op2_range, + relation_kind rel) { // Unary operation are allowed to pass a range in for second operand // as there are often additional restrictions beyond the type which @@ -72,7 +73,7 @@ gimple_range_calc_op1 (irange &r, const gimple *stmt, return true; } return gimple_range_handler (stmt)->op1_range (r, type, lhs_range, - op2_range); + op2_range, rel); } // Calculate what we can determine of the range of this statement's @@ -82,7 +83,8 @@ gimple_range_calc_op1 (irange &r, const gimple *stmt, bool gimple_range_calc_op2 (irange &r, const gimple *stmt, - const irange &lhs_range, const irange &op1_range) + const irange &lhs_range, const irange &op1_range, + relation_kind rel) { tree type = TREE_TYPE (gimple_range_operand2 (stmt)); // An empty range is viral. @@ -92,7 +94,7 @@ gimple_range_calc_op2 (irange &r, const gimple *stmt, return true; } return gimple_range_handler (stmt)->op2_range (r, type, lhs_range, - op1_range); + op1_range, rel); } // Return TRUE if GS is a logical && or || expression. @@ -1000,6 +1002,12 @@ gori_compute::compute_operand1_range (irange &r, gimple *stmt, int_range_max op1_range, op2_range; tree op1 = gimple_range_operand1 (stmt); tree op2 = gimple_range_operand2 (stmt); + relation_kind rel; + + if (op1 && op2) + rel = src.query_relation (op1, op2); + else + rel = VREL_NONE; // Fetch the known range for op1 in this block. src.get_operand (op1_range, op1); @@ -1008,7 +1016,7 @@ gori_compute::compute_operand1_range (irange &r, gimple *stmt, if (op2) { src.get_operand (op2_range, op2); - if (!gimple_range_calc_op1 (r, stmt, lhs, op2_range)) + if (!gimple_range_calc_op1 (r, stmt, lhs, op2_range, rel)) return false; } else @@ -1016,7 +1024,7 @@ gori_compute::compute_operand1_range (irange &r, gimple *stmt, // We pass op1_range to the unary operation. Nomally it's a // hidden range_for_type parameter, but sometimes having the // actual range can result in better information. - if (!gimple_range_calc_op1 (r, stmt, lhs, op1_range)) + if (!gimple_range_calc_op1 (r, stmt, lhs, op1_range, rel)) return false; } @@ -1077,12 +1085,18 @@ gori_compute::compute_operand2_range (irange &r, gimple *stmt, int_range_max op1_range, op2_range; tree op1 = gimple_range_operand1 (stmt); tree op2 = gimple_range_operand2 (stmt); + relation_kind rel; + + if (op1 && op2) + rel = src.query_relation (op1, op2); + else + rel = VREL_NONE; src.get_operand (op1_range, op1); src.get_operand (op2_range, op2); // Intersect with range for op2 based on lhs and op1. - if (!gimple_range_calc_op2 (r, stmt, lhs, op1_range)) + if (!gimple_range_calc_op2 (r, stmt, lhs, op1_range, rel)) return false; unsigned idx;