From patchwork Wed Apr 8 12:31:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 132809 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id BC4314BA2E16 for ; Wed, 8 Apr 2026 12:32:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC4314BA2E16 Authentication-Results: sourceware.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=igXAv67A; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=sAtVXfqE; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=igXAv67A; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=sAtVXfqE 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 [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id A47194BA540B for ; Wed, 8 Apr 2026 12:31:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A47194BA540B 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 A47194BA540B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775651509; cv=none; b=aiEw8+edONp1MDcuN5+FNOF83pmKybBTnZ/eBHS3sHJYMbSPi2NOuOM7hsqyImOzhRtfkw9ZUNf+4yspnHngLlNPnClS8zngzEAQyH66Mml+4/44M01/Z0CztSEzVviQvm30VZoJ9OzcNW8yW/8kthbjzexJWHVVTHjGgGUmTDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775651509; c=relaxed/simple; bh=fyMH9E02M4ZPYZi5PwKut5qOVZ7F3puYRObvQdNHnek=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=qURVsBq6iRpCBydhzDgrIjUVbbvOb61bD0YRisl8jswLHhHfMjMEGWboNCjLDObfKVBd513AG84XwjVQfSG6OJedinhOk9nTs/1odMNxPfO7Tks2DzEMJrfYKGH6viq/FCEAk+0m4NfpbVSAxftHKt1wC4yoM5TyYzbTDzuTMPA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A47194BA540B 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 8D72A4E9C5; Wed, 8 Apr 2026 12:31:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1775651507; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=O+TV1ug6PpO3aLc17owyxjtTDAuU6kqIBba9j9r6u+4=; b=igXAv67A4+NXKgj+zVIJyZwcLNaparLphwOxp1/qr5SgDzZpeOXegP0P+JWea6mCK0zkrO 9iY8N0GSccf/7dvoxwhdM2DJ08MGhBthSamJ5gkXNtD2EOyfIXArwFpbtKi39ttiWjbcqU CiSiyjbCfeJUDnO+6cJ/6Bmcao/nUqo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1775651507; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=O+TV1ug6PpO3aLc17owyxjtTDAuU6kqIBba9j9r6u+4=; b=sAtVXfqEfZLusNSPYV4laaFPHBxV1w0BX3zsV4wi2t34Ba6TsMeus3xbXLovSGxjABKgmu EzlcoFKXUKFhZVAQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=igXAv67A; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=sAtVXfqE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1775651507; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=O+TV1ug6PpO3aLc17owyxjtTDAuU6kqIBba9j9r6u+4=; b=igXAv67A4+NXKgj+zVIJyZwcLNaparLphwOxp1/qr5SgDzZpeOXegP0P+JWea6mCK0zkrO 9iY8N0GSccf/7dvoxwhdM2DJ08MGhBthSamJ5gkXNtD2EOyfIXArwFpbtKi39ttiWjbcqU CiSiyjbCfeJUDnO+6cJ/6Bmcao/nUqo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1775651507; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=O+TV1ug6PpO3aLc17owyxjtTDAuU6kqIBba9j9r6u+4=; b=sAtVXfqEfZLusNSPYV4laaFPHBxV1w0BX3zsV4wi2t34Ba6TsMeus3xbXLovSGxjABKgmu EzlcoFKXUKFhZVAQ== 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 8540E4A0B3; Wed, 8 Apr 2026 12:31:47 +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 SlmFILNK1mniagAAD6G6ig (envelope-from ); Wed, 08 Apr 2026 12:31:47 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] ipa: Type-convert constants in jump functions during inlining (PR124777) User-Agent: Notmuch/0.38.3 (https://notmuchmail.org) Emacs/30.2 (x86_64-suse-linux-gnu) Date: Wed, 08 Apr 2026 14:31:43 +0200 Message-ID: MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; 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)[]; TO_DN_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.cz:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from,2a07:de40:b281:106:10:150:64:167:received]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; MID_RHS_MATCH_FROMTLD(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from] X-Rspamd-Queue-Id: 8D72A4E9C5 X-Spam-Score: -4.51 X-Spam-Level: X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org Hi, PR 124777 revealed that update_jump_functions_after_inlining does not properly fold_convert constants when it propagates them from constant jump functions to formerly pass-through ones, leading to expectations of wrong constants in parameters leading to inserting bogus builtin_unreachables during inlining. This patch fixes it by calling ipacp_value_safe_for_type which is what IPA-CP uses during its propagation and moved handling of the case to a separate function. Bootstrapped and LTO-bootstrapped and tested on x86_64-linux. OK for master? Thanks, Martin gcc/ChangeLog: 2026-04-07 Martin Jambor PR ipa/124777 * ipa-cp.h (ipacp_value_safe_for_type): Declare. * ipa-cp.cc (ipacp_value_safe_for_type): Make public. * ipa-prop.cc (ipa_set_jf_cst_copy): Fix comment. (ipa_convert_prop_cst_jf): New function. (update_jump_functions_after_inlining): Handle the constant to pass-through case by calling ipa_convert_prop_cst_jf. gcc/testsuite/ChangeLog: 2026-04-07 Martin Jambor PR ipa/124777 * gcc.dg/ipa/pr124777.c: New test. --- gcc/ipa-cp.cc | 2 +- gcc/ipa-cp.h | 1 + gcc/ipa-prop.cc | 44 +++++++++++++++++++++++------ gcc/testsuite/gcc.dg/ipa/pr124777.c | 38 +++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr124777.c diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index e96b1dc8391..337fca71013 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -1544,7 +1544,7 @@ initialize_node_lattices (struct cgraph_node *node) propagated to a parameter of type PARAM_TYPE, or return a fold-converted VALUE to PARAM_TYPE if that is possible. Return NULL_TREE otherwise. */ -static tree +tree ipacp_value_safe_for_type (tree param_type, tree value) { if (!value) diff --git a/gcc/ipa-cp.h b/gcc/ipa-cp.h index 45da483e9ab..8191aac5c5b 100644 --- a/gcc/ipa-cp.h +++ b/gcc/ipa-cp.h @@ -323,6 +323,7 @@ bool ipa_vr_operation_and_type_effects (vrange &dst_vr, const ipa_vr &src_vr, enum tree_code operation, tree dst_type, tree src_type); +tree ipacp_value_safe_for_type (tree param_type, tree value); diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index ea7519a17d3..dee7632eef0 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -680,8 +680,8 @@ ipa_set_jf_unknown (struct ipa_jump_func *jfunc) jfunc->type = IPA_JF_UNKNOWN; } -/* Set JFUNC to be a copy of another jmp (to be used by jump function - combination code). The two functions will share their rdesc. */ +/* Set DST to be a copy of another SRC. The two functions will share their + rdesc. */ static void ipa_set_jf_cst_copy (struct ipa_jump_func *dst, @@ -693,6 +693,36 @@ ipa_set_jf_cst_copy (struct ipa_jump_func *dst, dst->value.constant = src->value.constant; } +/* Set DST to be a copy of another jump function SRC but possibly adjust it to + a new passed type PARM_TYPE. If the adjustment fails, the jump function can + end up being set to the unknown type. If the conversion is not necessary or + it succeeds and if the destination rdesc has not been already used, the two + functions will share their rdesc. */ + +static void +ipa_convert_prop_cst_jf (struct ipa_jump_func *dst, + struct ipa_jump_func *src, + tree parm_type) + +{ + gcc_checking_assert (src->type == IPA_JF_CONST); + tree new_val = ipacp_value_safe_for_type (parm_type, + ipa_get_jf_constant (src)); + if (new_val) + { + bool rd = ipa_get_jf_pass_through_refdesc_decremented (dst); + + dst->type = IPA_JF_CONST; + dst->value.constant.value = new_val; + if (!rd) + dst->value.constant.rdesc = src->value.constant.rdesc; + else + ipa_zap_jf_refdesc (dst); + } + else + ipa_set_jf_unknown (dst); +} + /* Set JFUNC to be a constant jmp function. */ static void @@ -3863,13 +3893,9 @@ update_jump_functions_after_inlining (struct cgraph_edge *cs, ipa_set_jf_unknown (dst); break; case IPA_JF_CONST: - { - bool rd = ipa_get_jf_pass_through_refdesc_decremented (dst); - ipa_set_jf_cst_copy (dst, src); - if (rd) - ipa_zap_jf_refdesc (dst); - } - + ipa_convert_prop_cst_jf (dst, src, + ipa_get_type (old_inline_root_info, + dst_fid)); break; case IPA_JF_PASS_THROUGH: diff --git a/gcc/testsuite/gcc.dg/ipa/pr124777.c b/gcc/testsuite/gcc.dg/ipa/pr124777.c new file mode 100644 index 00000000000..210eb7c36b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr124777.c @@ -0,0 +1,38 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-early-inlining" } */ + +int a; +char b; +void c() { + __builtin_exit(0); +} + +typedef short (*t_d)(unsigned); + +static short __attribute__((noclone)) +d(unsigned f) +{ + if (f == (unsigned)(unsigned short)-1) + c (); + for (; a; a++) + ; +} + +typedef short (*t_g)(unsigned, unsigned, unsigned short, t_d); + +static short __attribute__((noclone)) +g(unsigned f, unsigned h, unsigned short i, t_d p_d) { + if (f || h) + p_d(i); +} + +static unsigned __attribute__((noclone)) +j(unsigned f, signed char h, t_d p_d, t_g p_g) { + p_g(b, 1, h, p_d); +} + +int main() { + signed char e = -1; + j(0, e, d, g); + return 0; +}