From patchwork Sun Apr 28 20:09:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1928698 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bXZG7h09; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VSHdb3j6Dz23hv for ; Mon, 29 Apr 2024 06:10:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C08BB3858417 for ; Sun, 28 Apr 2024 20:10:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id B249E3858D33 for ; Sun, 28 Apr 2024 20:10:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B249E3858D33 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B249E3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714335023; cv=none; b=ERUuqwvN0lwT6DP0W6f/qc+5DseSKJIQZmHFQTsCfONoeKxRFOw0ygZY9LC/qajKEsQdbve/CJD5a4iihg93mg9DG5q6DMtgoAYUjEbOHq9zlXWfE0+o7qtQtzCt4Wa8AYaUaBL5oQKKC8SB3C0SHXHZ8VfWwMqSNZlb10Ce4FU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714335023; c=relaxed/simple; bh=YB7pBYcmHBnr8zpdHMjEUhdi/ikPT8lMLEeSsG2n56I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FMp8RbkJIHMKL7G6DLk0+5Gl5R7PEYPvJxZmQgX9izKcQOlN3n6ot7drlqEViyeX2E5AdyQOj0sCKnIUTWy6XA28k/4qPigRoq3IA14sTtFjywIsvcazgW6aVRV0nyb6nK29ykEpgKkqVJhQ5gAl933s3LIkGsxT40RrBFM2XGc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714335020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=A2zVmfY4st7P/gP5CpSd5pNjJx/tS2VzJNUrE7wERog=; b=bXZG7h09OIruSRXXcnVVwi0wHlA7oC0ctf6tffEwv+pqUP3WQR9Z7NdaP36eqPYtF0Lc6b JQ71TIwe1iCkEtkZ9reH7xRvAzWG9G5/0qrlE9BeLf/3CYqtpy5IkYK8jprHGSo6sEr/cA s+ql18xhwweUXAy/5NC+9igzBCDF5IY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-61-vjX9clHiNHi00HDqspAG0g-1; Sun, 28 Apr 2024 16:10:16 -0400 X-MC-Unique: vjX9clHiNHi00HDqspAG0g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A2601C0512A; Sun, 28 Apr 2024 20:10:16 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF5A7492BC7; Sun, 28 Apr 2024 20:10:15 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.2/8.17.1) with ESMTPS id 43SKADn91250025 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 28 Apr 2024 22:10:13 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.2/8.17.2/Submit) id 43SKADZJ1250024; Sun, 28 Apr 2024 22:10:13 +0200 From: Aldy Hernandez To: GCC patches Cc: Martin Jambor , Andrew MacLeod , Aldy Hernandez Subject: [PATCH] Minor range type fixes for IPA in preparation for prange. Date: Sun, 28 Apr 2024 22:09:19 +0200 Message-ID: <20240428200959.1249849-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org The polymorphic Value_Range object takes a tree type at construction so it can determine what type of range to use (currently irange or frange). It seems a few of the types are slightly off. This isn't a problem now, because IPA only cares about integers and pointers, which can both live in an irange. However, with prange coming about, we need to get the type right, because you can't store an integer in a pointer range or vice versa. Also, in preparation for prange, the irange::supports_p() idiom will become: irange::supports_p () || prange::supports_p() To avoid changing all these palces, I've added an inline function we can later change and change everything at once. Finally, there's a Value_Range::supports_type_p() && irange::supports_p() in the code. The latter is a subset of the former, so there's no need to check both. OK for trunk? gcc/ChangeLog: * ipa-cp.cc (ipa_vr_operation_and_type_effects): Use ipa_supports_p. (ipa_value_range_from_jfunc): Change Value_Range type. (propagate_vr_across_jump_function): Same. * ipa-cp.h (ipa_supports_p): New. * ipa-fnsummary.cc (evaluate_conditions_for_known_args): Change Value_Range type. * ipa-prop.cc (ipa_compute_jump_functions_for_edge): Use ipa_supports_p. (ipcp_get_parm_bits): Same. --- gcc/ipa-cp.cc | 14 +++++++------- gcc/ipa-cp.h | 8 ++++++++ gcc/ipa-fnsummary.cc | 2 +- gcc/ipa-prop.cc | 8 +++----- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index a688dced5c9..5781f50c854 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -1649,7 +1649,7 @@ ipa_vr_operation_and_type_effects (vrange &dst_vr, enum tree_code operation, tree dst_type, tree src_type) { - if (!irange::supports_p (dst_type) || !irange::supports_p (src_type)) + if (!ipa_supports_p (dst_type) || !ipa_supports_p (src_type)) return false; range_op_handler handler (operation); @@ -1720,7 +1720,7 @@ ipa_value_range_from_jfunc (vrange &vr, if (TREE_CODE_CLASS (operation) == tcc_unary) { - Value_Range res (vr_type); + Value_Range res (parm_type); if (ipa_vr_operation_and_type_effects (res, srcvr, @@ -1733,7 +1733,7 @@ ipa_value_range_from_jfunc (vrange &vr, Value_Range op_res (vr_type); Value_Range res (vr_type); tree op = ipa_get_jf_pass_through_operand (jfunc); - Value_Range op_vr (vr_type); + Value_Range op_vr (TREE_TYPE (op)); range_op_handler handler (operation); ipa_range_set_and_normalize (op_vr, op); @@ -2527,7 +2527,7 @@ propagate_vr_across_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc, if (src_lats->m_value_range.bottom_p ()) return dest_lat->set_to_bottom (); - Value_Range vr (operand_type); + Value_Range vr (param_type); if (TREE_CODE_CLASS (operation) == tcc_unary) ipa_vr_operation_and_type_effects (vr, src_lats->m_value_range.m_vr, @@ -2540,16 +2540,16 @@ propagate_vr_across_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc, { tree op = ipa_get_jf_pass_through_operand (jfunc); Value_Range op_vr (TREE_TYPE (op)); - Value_Range op_res (operand_type); + Value_Range op_res (param_type); range_op_handler handler (operation); ipa_range_set_and_normalize (op_vr, op); if (!handler - || !op_res.supports_type_p (operand_type) + || !ipa_supports_p (operand_type) || !handler.fold_range (op_res, operand_type, src_lats->m_value_range.m_vr, op_vr)) - op_res.set_varying (operand_type); + op_res.set_varying (param_type); ipa_vr_operation_and_type_effects (vr, op_res, diff --git a/gcc/ipa-cp.h b/gcc/ipa-cp.h index 7ff74fb5c98..abeaaa4053e 100644 --- a/gcc/ipa-cp.h +++ b/gcc/ipa-cp.h @@ -291,4 +291,12 @@ public: bool values_equal_for_ipcp_p (tree x, tree y); +/* Return TRUE if IPA supports ranges of TYPE. */ + +static inline bool +ipa_supports_p (tree type) +{ + return irange::supports_p (type); +} + #endif /* IPA_CP_H */ diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc index dff40cd8aa5..1dbf5278149 100644 --- a/gcc/ipa-fnsummary.cc +++ b/gcc/ipa-fnsummary.cc @@ -515,7 +515,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node, } else if (!op->val[1]) { - Value_Range op0 (op->type); + Value_Range op0 (TREE_TYPE (op->val[0])); range_op_handler handler (op->code); ipa_range_set_and_normalize (op0, op->val[0]); diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index b57f9750431..2d5c51298f2 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -2392,10 +2392,8 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, else { if (param_type - && Value_Range::supports_type_p (TREE_TYPE (arg)) - && Value_Range::supports_type_p (param_type) - && irange::supports_p (TREE_TYPE (arg)) - && irange::supports_p (param_type) + && ipa_supports_p (TREE_TYPE (arg)) + && ipa_supports_p (param_type) && get_range_query (cfun)->range_of_expr (vr, arg, cs->call_stmt) && !vr.undefined_p ()) { @@ -5763,7 +5761,7 @@ ipcp_get_parm_bits (tree parm, tree *value, widest_int *mask) ipcp_transformation *ts = ipcp_get_transformation_summary (cnode); if (!ts || vec_safe_length (ts->m_vr) == 0 - || !irange::supports_p (TREE_TYPE (parm))) + || !ipa_supports_p (TREE_TYPE (parm))) return false; int i = ts->get_param_index (current_function_decl, parm);