From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 26CCF3858D1E; Tue, 25 Apr 2023 07:38:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26CCF3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682408324; bh=n4j0TOjuFjwogLJI1nJLZ878Nwe9eEiVkeqL2w898go=; h=From:To:Subject:Date:From; b=QGY+xG1z5JQKMBjAqc/smmcu48TzsWUrihywCj31IU58Ez2BR4/C2hQ4/PH2c1cQj plnxPiW2ahDc2SPsqyhsyZdw4MIWHoHibiIX9xR6GrMRS9Edf8GjiCCx69IQzwRorB y6LQtnDm5cEA0PiywkgdkSqPH9CEFJDMEolo83ew= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-211] Pass correct type to irange::contains_p() in ipa-cp.cc. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: a4916881b74c36c613a8a7abe040bb197ea8ba75 X-Git-Newrev: 36d98023c8b8d2a2e286ab68b1d17402c217102d Message-Id: <20230425073844.26CCF3858D1E@sourceware.org> Date: Tue, 25 Apr 2023 07:38:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:36d98023c8b8d2a2e286ab68b1d17402c217102d commit r14-211-g36d98023c8b8d2a2e286ab68b1d17402c217102d Author: Aldy Hernandez Date: Mon Nov 21 23:18:43 2022 +0100 Pass correct type to irange::contains_p() in ipa-cp.cc. There is a call to contains_p() in ipa-cp.cc which passes incompatible types. This currently works because deep in the call chain, the legacy code uses tree_int_cst_lt which performs the operation with widest_int. With the upcoming removal of legacy, contains_p() will be stricter. gcc/ChangeLog: * ipa-cp.cc (ipa_range_contains_p): New. (decide_whether_version_node): Use it. Diff: --- gcc/ipa-cp.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index b3e0f62e400..65c49558b58 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -6180,6 +6180,23 @@ decide_about_value (struct cgraph_node *node, int index, HOST_WIDE_INT offset, return true; } +/* Like irange::contains_p(), but convert VAL to the range of R if + necessary. */ + +static inline bool +ipa_range_contains_p (const irange &r, tree val) +{ + if (r.undefined_p ()) + return false; + + tree type = r.type (); + if (!wi::fits_to_tree_p (wi::to_wide (val), type)) + return false; + + val = fold_convert (type, val); + return r.contains_p (val); +} + /* Decide whether and what specialized clones of NODE should be created. */ static bool @@ -6221,7 +6238,8 @@ decide_whether_version_node (struct cgraph_node *node) supports this only for integers now. */ if (TREE_CODE (val->value) == INTEGER_CST && !plats->m_value_range.bottom_p () - && !plats->m_value_range.m_vr.contains_p (val->value)) + && !ipa_range_contains_p (plats->m_value_range.m_vr, + val->value)) { /* This can happen also if a constant present in the source code falls outside of the range of parameter's type, so we