From patchwork Wed Mar 30 09:52:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1611008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=L4k4XW43; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=OPTU5LVS; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KT1vG1KB6z9sCq for ; Wed, 30 Mar 2022 20:52:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA0AF3888C54 for ; Wed, 30 Mar 2022 09:52:37 +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 [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 6E218385840F for ; Wed, 30 Mar 2022 09:52:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E218385840F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4873F1F37B for ; Wed, 30 Mar 2022 09:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1648633945; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=XhV7TWoDDQl2T2C7SAPezdYrykc0hXeojaj7cSTSbWA=; b=L4k4XW43XnTOYLetC5eYuncav44fa1kH8SDjIf6S1Ylepao7UMvFVba2qldMngEs1jsxwg ZQmZYv96yEMlUQ4JzLHVunKkgPFHTvfFigZkmwBYuFB3jSSdny4Zb+3Pb/mrZEk6V2spYE 4V95ni+jHnbukiowXkjOJEaXCfmzATw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1648633945; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=XhV7TWoDDQl2T2C7SAPezdYrykc0hXeojaj7cSTSbWA=; b=OPTU5LVSOVeF0givWILdmmL/rqq8QK4wNsVDEqVUKsb5tZ1EB6RM2bn+4YkUNu6tkkpRjs eewywEBGQJWtE7Cg== Received: from suse.cz (virgil.suse.cz [10.100.13.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 2FDE7A3B83 for ; Wed, 30 Mar 2022 09:52:25 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Subject: [GCC 9 backport] cplxlower: Avoid a transform when looking at a default definition User-Agent: Notmuch/0.35 (https://notmuchmail.org) Emacs/27.2 (x86_64-suse-linux-gnu) Date: Wed, 30 Mar 2022 11:52:24 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 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 Sender: "Gcc-patches" Hi, I did not backport my fix of PR 97456 to GCC 9 and it re-surfaced there as PR 105071. I have cherry-picked the fix, pasted below, on top of the gcc 9 branch (the only change is an extra bug reference in the ChangeLog) and made sure it passes bootstrap and testing on x86_64-linux. Can I commit the backport to the branch? I think the old testcase is sufficient and so did not add the new one. Thanks, Martin In PR 97456, IPA-SRA triggers a bug in tree-complex.c where it converts: a$_M_value_21 = COMPLEX_EXPR ; (where ISRA.18 is IPA-SRA created PARM_DECL with DECL_IGNORED_P set, which is why it only happens with IPA-SRA) into: a$_M_value_21 = COMPLEX_EXPR ; i.e. it replaces two uses of the parameter default-def with two uninitialized default-defs of a new variable - all in hope to produce code with better debug info. This patch fixes it by avoiding the transform when the SSA_NAME to be replaced is a default definition. gcc/ChangeLog: 2020-10-19 Martin Jambor PR tree-optimization/97456 PR middle-end/105071 * tree-complex.c (set_component_ssa_name): Do not replace ignored decl default definitions with new component vars. Reorder if conditions. gcc/testsuite/ChangeLog: 2020-10-19 Martin Jambor PR tree-optimization/97456 * gcc.dg/tree-ssa/pr97456.c: New test. (cherry picked from commit 619f91eaa8c8a50f1f9d3e7b96ee837037f0e806) --- gcc/testsuite/gcc.dg/tree-ssa/pr97456.c | 40 +++++++++++++++++++++++++ gcc/tree-complex.c | 3 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr97456.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr97456.c b/gcc/testsuite/gcc.dg/tree-ssa/pr97456.c new file mode 100644 index 00000000000..5171c9b4577 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr97456.c @@ -0,0 +1,40 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fwhole-program" } */ + + +float val2 = 1.710780f; +float val3; +volatile float vf; + +int __attribute__((noipa)) +get_bool (void) +{ + return 1; +} + +int __attribute__((noinline)) +wrong (float *pos) +{ + _Complex float a; + + __real__ a = *pos; + __imag__ a = *pos; + + _Complex float b = 0 + 0i; + + b = b + a; + + if (b == 0.0f) + return 1; + + vf = __imag__ b; + return 0; +} + +int main(int argc, char **argv) { + float val = get_bool () == 1 ? val2 : val3; + + if ((wrong(&val), wrong(&val))) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-complex.c b/gcc/tree-complex.c index d4b053d68e1..36a4d6f06d5 100644 --- a/gcc/tree-complex.c +++ b/gcc/tree-complex.c @@ -569,7 +569,8 @@ set_component_ssa_name (tree ssa_name, bool imag_p, tree value) { /* Replace an anonymous base value with the variable from cvc_lookup. This should result in better debug info. */ - if (SSA_NAME_VAR (ssa_name) + if (!SSA_NAME_IS_DEFAULT_DEF (value) + && SSA_NAME_VAR (ssa_name) && (!SSA_NAME_VAR (value) || DECL_IGNORED_P (SSA_NAME_VAR (value))) && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name))) {