From patchwork Tue Nov 5 11:29:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 2006857 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=uTSTappE; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=WVpmF16n; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=uTSTappE; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=WVpmF16n; 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 4XjR3405rlz1xyM for ; Tue, 5 Nov 2024 22:30:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2077E3857739 for ; Tue, 5 Nov 2024 11:30:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 41A253858023 for ; Tue, 5 Nov 2024 11:29:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41A253858023 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 41A253858023 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730806202; cv=none; b=JUqObUCZWHSllShjiNopZv04G5MhBh+rFIGXgiGl+1FUrp2eg8p5WU0Z1WMFZakTVBmLSw7apjZJMI81bwzJ+riqhV0jpH9dLakkApmMDCevpQxkrFIxTtRJogF2P1oiwkrw0hBd/QhTbD/VbBAEGv44NU2wHjbT2O3CHB1d5F4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730806202; c=relaxed/simple; bh=pnHXQmASAS4UV8VeFiV2nCjTOWheFj6Uq8PojQfO7Zw=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=tI9fle3+LEDMTL+9BDZClShX71DQyeySuxw1pf/CeI9g5TnDpUEBVNHj+fd4Gblu5rcYKVI0OY7HG994C2BRq9iflMRCzhrv+cYn33ZENjBjxHZWelkQ0E2L9aPtHfgeOJNQmq5PBHa7ThCWM+BI+H8NJM+QUFadrzs+zbQAvt0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out1.suse.de (Postfix) with ESMTPS id 1215D21D21; Tue, 5 Nov 2024 11:29:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1730806198; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eAJctLENjnjylYmPZk7tV//ZoXcnHFbs4IDGUoGG4Gs=; b=uTSTappE+3daHrfzDPQD4q700ZQO72Wknj8FP1OBOswLB8oUf4HNv1eQaNgPwjgwLkRVeL FbfWBUDv4C1bAAziAkuyQifbC4p924BP0lkB+HXqlhUGpV9m35irZDIqCkr8jr/WTn7nXS 8/BrB1ihM/VZi44vgYxpYFTG+cbEsCM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1730806198; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eAJctLENjnjylYmPZk7tV//ZoXcnHFbs4IDGUoGG4Gs=; b=WVpmF16nstoVvwhdmc+EqPdbk/B8GHfoRPtklqU2d2I1O2yYuNd/SvvYKAi2XAJ8nHk84h yRm3a6W3UWeZdgCA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=uTSTappE; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=WVpmF16n DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1730806198; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eAJctLENjnjylYmPZk7tV//ZoXcnHFbs4IDGUoGG4Gs=; b=uTSTappE+3daHrfzDPQD4q700ZQO72Wknj8FP1OBOswLB8oUf4HNv1eQaNgPwjgwLkRVeL FbfWBUDv4C1bAAziAkuyQifbC4p924BP0lkB+HXqlhUGpV9m35irZDIqCkr8jr/WTn7nXS 8/BrB1ihM/VZi44vgYxpYFTG+cbEsCM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1730806198; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eAJctLENjnjylYmPZk7tV//ZoXcnHFbs4IDGUoGG4Gs=; b=WVpmF16nstoVvwhdmc+EqPdbk/B8GHfoRPtklqU2d2I1O2yYuNd/SvvYKAi2XAJ8nHk84h yRm3a6W3UWeZdgCA== 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 08A321394A; Tue, 5 Nov 2024 11:29:58 +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 OgsWArYBKmczZQAAD6G6ig (envelope-from ); Tue, 05 Nov 2024 11:29:58 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Aldy Hernandez Subject: [PATCH 7/8] ipa: Verify that const jump functions have corresponding value range User-Agent: Notmuch/0.38.3 (https://notmuchmail.org) Emacs/29.4 (x86_64-suse-linux-gnu) Date: Tue, 05 Nov 2024 12:29:53 +0100 Message-ID: MIME-Version: 1.0 X-Rspamd-Queue-Id: 1215D21D21 X-Rspamd-Action: no action X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; MID_RHS_MATCH_FROMTLD(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,suse.cz:dkim,virgil.suse.cz:mid,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.cz:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.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 Hi, Because the simplified way of extracting value ranges from functions does not look at scalar constants (as one of the versions had been doing before) but instead rely on the value range within the jump function already capturing the constant, I have added a verifier that it is indeed so. After the fixes in the previous patches, the verifier passes bootstrap and testsuite. The verifier is however a bit lenient when it comes to pranges. When a prange for an ADDR_EXPR of a DECL results in a non-NULL prange adjusted with known alignment, but this is then converted to an integer because that is what the compiled source does as is the case for example in testcase gcc.c-torture/compile/pr71109.c. While as long as we track the address in a prange we do capture the non-nullness: [prange] void (*) (void) [1, +INF] MASK 0xfffffffffffffffe VALUE 0x0 when it the range is folded into an integer we get Value range: [irange] int [-INF, +INF] MASK 0xfffffffe VALUE 0x0 which can contain zero. I have not looked into detail whether there is anything we can do about this case or what it would be. 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-cp.cc (ipa_check_const_jf_vr): New function. (ipa_value_range_from_jfunc): Call it when checking and when dealing with a constant jump function. (propagate_vr_across_jump_function): Likewise. --- gcc/ipa-cp.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 92dd2af19e0..f979fcd561d 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -1682,6 +1682,51 @@ ipa_vr_operation_and_type_effects (vrange &dst_vr, dst_type, src_type); } +/* Given a constant function JFUNC, check that VR also contains all that should + have been deduced at the call-site, PARAM_TYPE is the type of the + parameter. */ + +DEBUG_FUNCTION void +ipa_check_const_jf_vr (ipa_jump_func *jfunc, const vrange &vr, + tree param_type) +{ + if (vr.singleton_p ()) + return; + + tree val = ipa_get_jf_constant (jfunc); + if (!ipa_vr_supported_type_p (TREE_TYPE (val))) + return; + + if (POINTER_TYPE_P (TREE_TYPE (val))) + { + /* TODO: Non-nullness is sometimes lost here. */ + if (!POINTER_TYPE_P (param_type)) + return; + bool strict_overflow = false; + if (zerop (val)) + { + if (is_a (vr) && vr.zero_p ()) + return; + } + else if (tree_single_nonzero_warnv_p (val, &strict_overflow)) + { + tree zero = build_zero_cst (param_type); + if (!vr.contains_p (zero)) + return; + } + else + return; + } + fprintf (stderr, "Value range has not picked up expected information " + "for an IPA invariant:\n"); + fprintf (stderr, "Jump function: "); + ipa_dump_jump_function (stderr, jfunc); + fprintf (stderr, "Value range: "); + vr.dump (stderr); + fprintf (stderr, "\n"); + gcc_unreachable (); +} + /* Given a PASS_THROUGH jump function JFUNC that takes as its source SRC_VR of SRC_TYPE and the result needs to be DST_TYPE, if any value range information can be deduced at all, intersect VR with it. */ @@ -1747,6 +1792,10 @@ ipa_value_range_from_jfunc (vrange &vr, *jfunc->m_vr, NOP_EXPR, parm_type, jfunc->m_vr->type ()); + + if (flag_checking && jfunc->type == IPA_JF_CONST) + ipa_check_const_jf_vr (jfunc, vr, parm_type); + if (vr.singleton_p ()) return; @@ -2540,6 +2589,9 @@ propagate_vr_across_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc, param_type, jfunc->m_vr->type ()); + if (flag_checking && jfunc->type == IPA_JF_CONST) + ipa_check_const_jf_vr (jfunc, vr, param_type); + if (jfunc->type == IPA_JF_PASS_THROUGH) { ipa_node_params *caller_info = ipa_node_params_sum->get (cs->caller);