From patchwork Tue Jul 2 13:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 1955316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gjlay.de header.i=@gjlay.de header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=Up+7dgsg; dkim=pass header.d=gjlay.de header.i=@gjlay.de header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=6hRyCBEv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WD3y437c9z1xqb for ; Tue, 2 Jul 2024 23:42:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B6BFC38A8171 for ; Tue, 2 Jul 2024 13:42:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.25]) by sourceware.org (Postfix) with ESMTPS id AE0A13882109 for ; Tue, 2 Jul 2024 13:42:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE0A13882109 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE0A13882109 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=85.215.255.25 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1719927743; cv=pass; b=j4sTE9oKPOg8MkufNkJj6m/3P0dxm7D58jxXSnOW7OcN/z9wZ0okl1Uw76doTPF+pcuvbMKxF+Qg6JMF5B6gKfi4hPr1sDTurvjBH0PpDmTGSBDz8pA9ewpjQaR1kstpuosR4TVN3QIVNNASe0VXWZ3bU0DhG0nPjSsd6NVv4P0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1719927743; c=relaxed/simple; bh=3dLheLbaIrFO7OBG9eulfqEf/bvt2X2jMIx79+A1aTY=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From: To:Subject; b=HWKcnQ6cjhtzIPT0TWZRw/4XxQx/YLoZXTvWUr8imdd+2pBBgklV9RxYV0rLB0OHMrc5OnEbS6fQU2N0k7JdTYMPk+qZOyfGwgZlUtBEHNSfThXprJyxD90feIpELzDn5be/48zOHfYGerr+w3kPxu8nurxN0dzjCV2wSvrYk0s= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1719927738; cv=none; d=strato.com; s=strato-dkim-0002; b=mtJ7v6Tv0R47FA9t8aeAy/3ItbdxndQ1FWmhcQTLYP9HAEy6zch4ZfKv6M/81cB0aq mHtnP2SCQaNQHRQeVaoS+U120ppREm5eY19CjDBRfY3MbQU0oVyMJrMuZmki6cUmP/qB 1KNRBeaB9dfBDFMyFryxDEe4I78acdzher5Qsmkwl+WI1oxEdU16ooKTXXUZ469+iwNt gMHbL9HJLcc4RLsFlNOWeJwEVEY8l87kJ6nJzwjfP7etaN2uMlyBxfJ5/9Qn45bSrw+g LiG7QLbfU/Nq6hn5qvHGS7RYqMJKmY8mZvvIpmgVMAn+ZWPUYbAWuVmW+OecE6hHGpUo b4rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1719927738; s=strato-dkim-0002; d=strato.com; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=XAjdWy3T708e5MGKxfcgVwO6DpHjLyyrVsZ44I+lzR4=; b=ofjI5msyWOyPYsTfxLSESf4h6K8jYxIN7qZVQx70QoLTnQP6kardVcrllfCF2L8lUZ RXP+klGCmt/kj9IIFD5DPe3f1LAX1r7iN564AqEckgIegn/cXZK8dBvIBoerib9jFaR5 FVdHM4zd7FtJJJfiHjZjkv721kQ/6IOBQBkXZSOL0rYGY26T1vOIA5C1G4tVj8cvWh26 cRx0/DVgFUJzn4u5mfGqdt6AaFyEw4J4LAD533FbnSmJ624Lyn78pj5BBTjeOCVSgn4B YjiZDlsO6yhywJHfq6MYGISxtdJp9NuUwsJqNOEtRQwKtl6qMkLDkbMd/gEB/4ZeCc13 DbJg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1719927738; s=strato-dkim-0002; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=XAjdWy3T708e5MGKxfcgVwO6DpHjLyyrVsZ44I+lzR4=; b=Up+7dgsgzF9fV63tzMgn0hGczHC7i7gWINAGhuIwMWfW/kEkrcKCb17RKyNJApjH5G oeq6Q4muoNIsDkbYAyp7QDfpZo0GaBsmQBSXJoYMCw4vpwwg8snftJnjrukOTo/aKTV1 9PmNTygh6OckWCy1ljvDiVtpbnpcVDklmNCIG8SX4DoulGbMnGTL99Mvuy0zPB0SKX3C Hu8se/mVrfcQU9UaoRy8d7MXzOkZhTj+lDzVcjll3n5PxjbUz+njrF25g6isIiHHQOeO ZY+XwAl0/gMRhx24qBAeEFyiA+4PVBafTUSjECdtTb4I950cWAL+4vQE0CrsBy+aTz21 cBxw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1719927738; s=strato-dkim-0003; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=XAjdWy3T708e5MGKxfcgVwO6DpHjLyyrVsZ44I+lzR4=; b=6hRyCBEv5QuoAN4S6DOA+Bb3Ai2ay5mzdnwEpn9ZPtUglb7gjLL+hA8Vvobs0JOXqD d2e1ZYJna5Vwo4mZ3oAQ== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkbjtK7q2y9LkX3jYYP" Received: from [192.168.2.102] by smtp.strato.de (RZmta 50.5.0 DYNA|AUTH) with ESMTPSA id x05778062DgIO9l (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 2 Jul 2024 15:42:18 +0200 (CEST) Message-ID: <78bc7fef-20cd-4161-905c-6b93582974ec@gjlay.de> Date: Tue, 2 Jul 2024 15:42:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Georg-Johann Lay Content-Language: en-US To: "gcc-patches@gcc.gnu.org" , Jeff Law Subject: [patch,avr] PR87376: Disable -ftree-ter X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi Jeff, This is a patch to get correct code out of 64-bit loads from address-space __memx. The AVR address-spaces may require that move insns issue calls to library support functions, a fact that -ftree-ter doesn't account for. tree-ssa-ter.cc then replaces an expression across such a library call, resulting in wrong code. This patch disables that pass per default on avr, as there is no more fine grained way to avoid malicious optimizations. The pass can still be re-enabled by means of explicit -ftree-ter. Ok to apply? As an alternative, the option could be disabled permanently in avr.cc::avr_option_override(). Johann --- AVR: middle-end/87376 - Use -fno-tree-ter per default. Temporary expression replacement might replace expressions across library calls, for example with move insn from address-space __memx like in PR87376. -ftree-ter has no way where the backend could hook in to avoid only problematic replacements, thus kick it out altogether. PR middle-end/87376 gcc/ * common/config/avr/avr-common.cc (avr_option_optimization_table) : Set to 0. gcc/testsuite/ * gcc.target/avr/torture/pr87376-memx.c: New test. diff --git a/gcc/common/config/avr/avr-common.cc b/gcc/common/config/avr/avr-common.cc index fdf130f1e1a..2300d602cfe 100644 --- a/gcc/common/config/avr/avr-common.cc +++ b/gcc/common/config/avr/avr-common.cc @@ -32,6 +32,11 @@ static const struct default_options avr_option_optimization_table[] = // The only effect of -fcaller-saves might be that it triggers // a frame without need when it tries to be smart around calls. { OPT_LEVELS_ALL, OPT_fcaller_saves, NULL, 0 }, + // Temporary expression replacement might replace expressions across + // library calls, for example with move insn from address-space __memx + // like in PR87376. -ftree-ter has no way where the backend could hook + // in to avoid only problematic replacements, thus kick it out altogether. + { OPT_LEVELS_ALL, OPT_ftree_ter, NULL, 0 }, { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_mgas_isr_prologues, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_mmain_is_OS_task, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_mfuse_add_, NULL, 1 }, diff --git a/gcc/testsuite/gcc.target/avr/torture/pr87376-memx.c b/gcc/testsuite/gcc.target/avr/torture/pr87376-memx.c new file mode 100644 index 00000000000..e8373854ac8 --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr87376-memx.c @@ -0,0 +1,33 @@ +/* { dg-do run { target { ! avr_tiny } } } */ +/* { dg-additional-options "-std=gnu99" } */ + +typedef __UINT64_TYPE__ uint64_t; + +extern const __memx uint64_t aa __asm ("real_aa"); +extern const uint64_t bb __asm ("real_bb"); + +const __memx uint64_t real_aa = 0x1122334455667788; +const uint64_t real_bb = 0x0908070605040302; + +__attribute__((noinline,noclone)) +uint64_t add1 (void) +{ + return aa + bb; +} + +__attribute__((noinline,noclone)) +uint64_t add2 (void) +{ + return bb + aa; +} + +int main (void) +{ + if (add1() != 0x1a2a3a4a5a6a7a8a) + __builtin_exit (__LINE__); + + if (add2() != 0x1a2a3a4a5a6a7a8a) + __builtin_exit (__LINE__); + + return 0; +}