From patchwork Tue Nov 5 11:30:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 2006858 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=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=pwcRvsN1; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=WQwYUcN3; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=pwcRvsN1; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=WQwYUcN3; 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 4XjR4808Pbz1xyM for ; Tue, 5 Nov 2024 22:31:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 242303858027 for ; Tue, 5 Nov 2024 11:31:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id C62EE3857358 for ; Tue, 5 Nov 2024 11:30:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C62EE3857358 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C62EE3857358 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730806258; cv=none; b=ABaBgKlh7Wm94wEnSdiq4Zb+66niKKT4s8RGfTwexPkQWlyy/tssgcInw+jV5m0pqdryhu1r3dlkOSW2o0C4oFFLvTyDIdxnePS0KRr/DXT0tBQdHCacpnLHVIiJkHGTx7fbBT4ZTA0nARvlTfZhzv834gvVnr5zL+uKEp9+TzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730806258; c=relaxed/simple; bh=l/Z+dXoa0+cP5eGJopQHXT7UMK2NnY1ID3N9MtLm9n0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=rq03F17I0zZez1Z0CbroF+ex6KLXTmr5WK/SN1EUG2mX07Z3x9xR2zFwhMEl5U/GDeEJ9MQLRcuDZAwXuOoPF3CBBZFdplgxlTBMuIm500XCyBDSzWmMHWSoJWKa8atjLBJn8QMG+7sCo/A9Cfg1ENq19SWZJHAqJpEJEhLxTKk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id C9BA51FBEF; Tue, 5 Nov 2024 11:30:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1730806250; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=b2q8cfoXJO6z6ETEoYnsz8JnSO4FCa60Pbn0OmL8njM=; b=pwcRvsN1kCowOXSJJGOPwfpNtYf7+UNgx1MLjh3PoIMfyvO76tXakrHClL8lbkehzNwbTv lb+eXnvGb7kUcKbU125RdkM2A/hkj5E1w609ylWK5Yen81Q9ixq0tKfHyPHxP62DySRUFu fNzqFtvmQBlymKNA7T84jkugup5vtHE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1730806250; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=b2q8cfoXJO6z6ETEoYnsz8JnSO4FCa60Pbn0OmL8njM=; b=WQwYUcN3kSkrYwf4cpft8SUfFRxfYws1e7GYd6yCxGNzLERRIrq3az0JfuzANrFOEB9CY/ KdwsCsc1xqcWK9Ag== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1730806250; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=b2q8cfoXJO6z6ETEoYnsz8JnSO4FCa60Pbn0OmL8njM=; b=pwcRvsN1kCowOXSJJGOPwfpNtYf7+UNgx1MLjh3PoIMfyvO76tXakrHClL8lbkehzNwbTv lb+eXnvGb7kUcKbU125RdkM2A/hkj5E1w609ylWK5Yen81Q9ixq0tKfHyPHxP62DySRUFu fNzqFtvmQBlymKNA7T84jkugup5vtHE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1730806250; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=b2q8cfoXJO6z6ETEoYnsz8JnSO4FCa60Pbn0OmL8njM=; b=WQwYUcN3kSkrYwf4cpft8SUfFRxfYws1e7GYd6yCxGNzLERRIrq3az0JfuzANrFOEB9CY/ KdwsCsc1xqcWK9Ag== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BF84B1394A; Tue, 5 Nov 2024 11:30:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Kt+jLuoBKmejZQAAD6G6ig (envelope-from ); Tue, 05 Nov 2024 11:30:50 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Aldy Hernandez Subject: [PATCH 8/8] ipa: Improve how we derive value ranges from IPA invariants User-Agent: Notmuch/0.38.3 (https://notmuchmail.org) Emacs/29.4 (x86_64-suse-linux-gnu) Date: Tue, 05 Nov 2024 12:30:46 +0100 Message-ID: MIME-Version: 1.0 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROMTLD(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[ipa-cp.cc:url, virgil.suse.cz:mid, ipa-prop.cc:url, imap1.dmz-prg2.suse.org:helo, suse.cz:email] 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 Hi, I believe that the current function ipa_range_set_and_normalize lacks a check that a base of an ADDR_EXPR lacks a test whether the base really cannot be NULL, so this patch adds it. Moreover, I never liked the name as I do not think it makes the value of ranges any more normal but rather just special-cases non-zero ip_invariant pointers. Therefore, I have given it a different name and moved it to a .cc file, our LTO bootstrap should inline (and/or split) it if necessary anyway. Bootstrapped and tested on x86_64-linux, the whole patch series has additionally passed LTO and profiled-LTO bootstrap on the same platform and a bootstrap and testsuite on ppc64-linux. Aarch64-linux bootstrap and testing is in progress. OK for master is that passes too? Thanks, Martin gcc/ChangeLog: 2024-11-04 Martin Jambor * ipa-prop.h (ipa_get_range_from_ip_invariant): Declare. (ipa_range_set_and_normalize): Remove. * ipa-prop.cc (ipa_get_range_from_ip_invariant): New function. * ipa-cp.cc (ipa_vr_intersect_with_arith_jfunc): Use ipa_get_range_from_ip_invariant instead of ipa_range_set_and_normalize. * ipa-fnsummary.cc (evaluate_conditions_for_known_args): Likewise. --- gcc/ipa-cp.cc | 2 +- gcc/ipa-fnsummary.cc | 4 ++-- gcc/ipa-prop.cc | 17 +++++++++++++++++ gcc/ipa-prop.h | 15 +-------------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index f979fcd561d..83e30b6be55 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -1756,7 +1756,7 @@ ipa_vr_intersect_with_arith_jfunc (vrange &vr, if (!handler) return; value_range op_vr (TREE_TYPE (operand)); - ipa_range_set_and_normalize (op_vr, operand); + ipa_get_range_from_ip_invariant (op_vr, operand); tree operation_type; if (TREE_CODE_CLASS (operation) == tcc_comparison) diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc index e921cd495f6..6a28ecd873c 100644 --- a/gcc/ipa-fnsummary.cc +++ b/gcc/ipa-fnsummary.cc @@ -519,7 +519,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node, value_range op0 (TREE_TYPE (op->val[0])); range_op_handler handler (op->code); - ipa_range_set_and_normalize (op0, op->val[0]); + ipa_get_range_from_ip_invariant (op0, op->val[0]); if (!handler || !res.supports_type_p (op->type) @@ -538,7 +538,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node, value_range val_vr (TREE_TYPE (c->val)); range_op_handler handler (c->code); - ipa_range_set_and_normalize (val_vr, c->val); + ipa_get_range_from_ip_invariant (val_vr, c->val); if (!handler || !val_vr.supports_type_p (TREE_TYPE (c->val)) diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 3ff4753653b..07e3c62eb07 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -2312,6 +2312,23 @@ ipa_set_jfunc_vr (ipa_jump_func *jf, const ipa_vr &vr) ipa_set_jfunc_vr (jf, tmp); } +/* Given VAL that conforms to is_gimple_ip_invariant, produce a VRANGE that + represents it as a range. */ + +void +ipa_get_range_from_ip_invariant (vrange &r, tree val) +{ + if (TREE_CODE (val) == ADDR_EXPR) + { + bool strict_overflow = false; + if (tree_single_nonzero_warnv_p (val, &strict_overflow)) + r.set_nonzero (TREE_TYPE (val)); + else + r.set_varying (TREE_TYPE (val)); + } + else + r.set (val, val); +} /* If T is an SSA_NAME that is a result of a simple type conversion statement, return the operand of that conversion, otherwise treturn T. */ diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 3215395286b..e0064b4b2c9 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -1257,7 +1257,7 @@ tree ipcp_get_aggregate_const (struct function *func, tree parm, bool by_ref, HOST_WIDE_INT bit_size); bool unadjusted_ptr_and_unit_offset (tree op, tree *ret, poly_int64 *offset_ret); - +void ipa_get_range_from_ip_invariant (vrange &r, tree val); void ipa_prop_cc_finalize (void); /* From tree-sra.cc: */ @@ -1266,19 +1266,6 @@ tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree, /* In ipa-cp.cc */ void ipa_cp_cc_finalize (void); - -/* Set R to the range of [VAL, VAL] while normalizing addresses to - non-zero. */ - -inline void -ipa_range_set_and_normalize (vrange &r, tree val) -{ - if (TREE_CODE (val) == ADDR_EXPR) - r.set_nonzero (TREE_TYPE (val)); - else - r.set (val, val); -} - bool ipa_return_value_range (value_range &range, tree decl); void ipa_record_return_value_range (value_range val); bool ipa_jump_functions_equivalent_p (ipa_jump_func *jf1, ipa_jump_func *jf2);