From patchwork Fri Oct 16 18:46:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1383503 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CCZr82KStz9sSf for ; Sat, 17 Oct 2020 05:46:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E83B83954C0B; Fri, 16 Oct 2020 18:46:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 08474385ED4D for ; Fri, 16 Oct 2020 18:46:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 08474385ED4D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mjambor@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D27F6AD43 for ; Fri, 16 Oct 2020 18:46:39 +0000 (UTC) From: Martin Jambor To: GCC Patches Subject: [PATCH] cplxlower: Avoid a transform when looking at a default definition User-Agent: Notmuch/0.31 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Fri, 16 Oct 2020 20:46:39 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-3039.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Richard Biener Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, 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. Bootstrapped and tested on x86_64-linux. OK for trunk and the gcc-10 branch? Thanks, Martin gcc/ChangeLog: 2020-10-16 Martin Jambor PR tree-optimization/97456 * 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-16 Martin Jambor PR tree-optimization/97456 * gcc.dg/tree-ssa/pr97456.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr97456.c | 40 +++++++++++++++++++++++++ gcc/tree-complex.c | 6 ++-- 2 files changed, 44 insertions(+), 2 deletions(-) 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 2e54bbb917c..71ad7c18523 100644 --- a/gcc/tree-complex.c +++ b/gcc/tree-complex.c @@ -570,8 +570,10 @@ 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) - && (!SSA_NAME_VAR (value) || DECL_IGNORED_P (SSA_NAME_VAR (value))) - && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name))) + && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name)) + && (!SSA_NAME_VAR (value) + || (DECL_IGNORED_P (SSA_NAME_VAR (value)) + && !SSA_NAME_IS_DEFAULT_DEF (value)))) { comp = get_component_var (SSA_NAME_VAR (ssa_name), imag_p); replace_ssa_name_symbol (value, comp);