From patchwork Fri Apr 5 12:53:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 88100 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4412A3846410 for ; Fri, 5 Apr 2024 12:54:12 +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 [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id D48C0384601E for ; Fri, 5 Apr 2024 12:53:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D48C0384601E 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 D48C0384601E 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=1712321624; cv=none; b=unuV5y2yTsxK9XxIVB6+eEeON6YEty6DA8/VBRFjaJGO/dxONtodNdJvkFZNy37wiEsi5sN8rP7Dfn9LMURpUwtUAIaA7FMk+VkuR0vjvL3yvux8syskTHWrrJ5y0/IPuvfBjzWY8JodbBdty1MnE0RuCPqQXsm4/THU+7qWMGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712321624; c=relaxed/simple; bh=bJ9oflrXwN9HZE4TE79qlJxGY5Fzk3dhmKF3fooFGBw=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=TBMK5dZCDDmkj2z+1LbTasMtXXi9vFERbftJMWgzrbpqMp9tLf+Bywp9L9NzSKAcmB4/jYT7HxNh0ulRUmOEOcwmsqyBmWXWxmiOa0WPThh3KtCCtRFwqVSwQwAFbpi9QVXHTRHodVXS7W1n6kS3rfED08X5nQor9/6K5QD6Md4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 B568F21A3F; Fri, 5 Apr 2024 12:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1712321621; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=lqDf9wKci1O72W8WFXnHJFb6VvJHQaKuJIzFmYTAcMM=; b=tJrrZ/7kZdKQRaQAmVVIzvLQHUemp5KsLBrPU5ehmEH6YIIAmU6b8i7JLxUt24ueAH/XVa Ig8vUlsMIRlqX8gSFGCH87gN2PtNaoUclk/S1Fh02lyLZCNWsWg5rjTgHj9MP50zYpyQUr ps1ULHm2LqQecEPXu5aWHudyz8WlQo4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1712321621; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=lqDf9wKci1O72W8WFXnHJFb6VvJHQaKuJIzFmYTAcMM=; b=su1fsyyViEPCEM/n0X31bu37jYskAxMAl6TxlH7d0zSjfVOxR0762nud3tzp3R3T7agm8X kgzHqmvLTp9a3ABg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1712321620; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=lqDf9wKci1O72W8WFXnHJFb6VvJHQaKuJIzFmYTAcMM=; b=Gwpvem4SrMh9IbrtdkCr7zY3xzcGSa5nKDiqiHaih9MhD1QUgYk8xB1fDfsSMs8gIEYwsM p7bpqmB43I5S/nkWaEB7FiUJTXXwADHiQHfEmYDUWkfcxsvUAWy1EcvhBQ3qB3rzEY7F9J 8LCRcdwAS5PIcitUwi8xGxlTQcbl5Is= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1712321620; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=lqDf9wKci1O72W8WFXnHJFb6VvJHQaKuJIzFmYTAcMM=; b=yneRrQFn5VhQU2FoFlhBUfkpJS0EFVr9JjepC5JCPAOsFtRfm+e2T+INFTkki+4K7PUp6N D/1dEClkO9TncKDA== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id AF4B3139E8; Fri, 5 Apr 2024 12:53:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id e87EKlT0D2YEIQAAn2gu4w (envelope-from ); Fri, 05 Apr 2024 12:53:40 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] ipa: Force args obtined through pass-through maps to the expected type (PR 113964) User-Agent: Notmuch/0.38.2 (https://notmuchmail.org) Emacs/29.3 (x86_64-suse-linux-gnu) Date: Fri, 05 Apr 2024 14:53:36 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Level: 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)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; MID_RHS_MATCH_FROMTLD(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; 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)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email, imap2.dmz-prg2.suse.org:helo, imap2.dmz-prg2.suse.org:rdns] X-Spam-Score: -4.30 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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+patchwork=sourceware.org@gcc.gnu.org Hi, interactions of IPA-CP and IPA-SRA on the same data is a rather big source of issues, I'm afraid. PR 113964 is a situation where IPA-CP propagates an unsigned short in a union parameter into a function which itself calls a different function which has a same union parameter and both these union parameters are split with IPA-SRA. The leaf function however uses a signed short member of the union. In the calling function, we get the unsigned constant as the replacement for the union and it is then passed in the call without any type compatibility checks. Apparently on riscv64 it matters whether the parameter is signed or unsigned short and so the leaf function can see different values. Fixed by using useless_type_conversion_p at the appropriate place and if it fails, use force_value_to type as elsewhere in similar situations. Bootstrapped and tested on x86_64-linux, the reporter has also run the testsuite with this patch on riscv64 and reported in Bugzilla there were no issues. OK for master and GCC 13? Thanks, Martin gcc/ChangeLog: 2024-04-04 Martin Jambor PR ipa/113964 * ipa-param-manipulation.cc (ipa_param_adjustments::modify_call): Force values obtined through pass-through maps to the expected split type. gcc/testsuite/ChangeLog: 2024-04-04 Patrick O'Neill Martin Jambor PR ipa/113964 * gcc.dg/ipa/pr114247.c: New test. --- gcc/ipa-param-manipulation.cc | 6 ++++++ gcc/testsuite/gcc.dg/ipa/pr114247.c | 31 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr114247.c diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc index 3e0df6a6f77..b4ca78b652e 100644 --- a/gcc/ipa-param-manipulation.cc +++ b/gcc/ipa-param-manipulation.cc @@ -740,6 +740,12 @@ ipa_param_adjustments::modify_call (cgraph_edge *cs, } if (repl) { + if (!useless_type_conversion_p(apm->type, repl->typed.type)) + { + repl = force_value_to_type (apm->type, repl); + repl = force_gimple_operand_gsi (&gsi, repl, + true, NULL, true, GSI_SAME_STMT); + } vargs.quick_push (repl); continue; } diff --git a/gcc/testsuite/gcc.dg/ipa/pr114247.c b/gcc/testsuite/gcc.dg/ipa/pr114247.c new file mode 100644 index 00000000000..60aa2bc0122 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr114247.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fsigned-char -fno-strict-aliasing -fwrapv" } */ + +union a { + unsigned short b; + int c; + signed short d; +}; +int e, f = 1, g; +long h; +const int **i; +void j(union a k, int l, unsigned m) { + const int *a[100]; + i = &a[0]; + h = k.d; +} +static int o(union a k) { + k.d = -1; + while (1) + if (f) + break; + j(k, g, e); + return 0; +} +int main() { + union a n = {1}; + o(n); + if (h != -1) + __builtin_abort(); + return 0; +}