From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 22D75384F02A for ; Thu, 1 Jul 2021 10:31:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22D75384F02A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F34A01FF9D for ; Thu, 1 Jul 2021 10:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1625135461; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=1RSKynfKOO8wbFxdBOKYBHJ4Wn+1IqdpoK/IK45AO0M=; b=WG7Oy40TKbGsAw35oUAVVwdQUeXdWyKyUiUMGS+3Y+bgZyqZ1mJItKCdN4s3NRKtU+Xo2a JQk63OXH6m+H6jAxxZhmTbMWt2YZYrHYqchaMjoPZZRXidUQ+FZoOD5nJLCdU8nFsXAWn7 E7pw7wZrb0dkG2u0+7XLb2MeSI5Dx4U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1625135461; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=1RSKynfKOO8wbFxdBOKYBHJ4Wn+1IqdpoK/IK45AO0M=; b=fWA67TL9wF2+LUruDduJDeaPIGaxWZf/0TyleBe2Q7tgGPFcZC964g3sn6jZXJTdSFAKN5 gPioZWJsEwwWN8Dw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id D2DA611CC0 for ; Thu, 1 Jul 2021 10:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1625135460; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=1RSKynfKOO8wbFxdBOKYBHJ4Wn+1IqdpoK/IK45AO0M=; b=Vid/UrKkpE1UBf0TcIAwgVR/KH+ibyKWIAzR9MLd9obOAAVn1YBNU9XvMeNhn9flbalByJ f6dtAZiP00XOhbNbXtHwGgw1VjtiWSYlPSvyKQCT6/XQ1zrFAB6zJK2n4PiLGYfbsW+Kn9 tt1ehCLluXfnz1OopDqHmmsy4zJLuqM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1625135460; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=1RSKynfKOO8wbFxdBOKYBHJ4Wn+1IqdpoK/IK45AO0M=; b=kM4+1FepEvGQ+rTssCB7l0cJJRJQsvOwLpZ8sg6x7UWVVQAsLsy71FlHUzaybTZPLA8od9 ZWYtITg9qTyJKODg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id dyF4MmSZ3WCdWgAALh3uQQ (envelope-from ) for ; Thu, 01 Jul 2021 10:31:00 +0000 Date: Thu, 1 Jul 2021 12:31:00 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/101278 - handle self-use in DSE analysis Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.1 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.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: , X-List-Received-Date: Thu, 01 Jul 2021 10:31:07 -0000 DSE store classification short-cuts the to-be classified stmt itself from chaining but fails to first check whether the store uses itself which can be the case when it is a call with the LHS also passed by value as argument. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-07-01 Richard Biener PR tree-optimization/101278 * tree-ssa-dse.c (dse_classify_store): First check for uses, then ignore stmt for chaining purposes. * gcc.dg/torture/pr101278.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr101278.c | 21 +++++++++++++++++++++ gcc/tree-ssa-dse.c | 10 +++++----- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr101278.c diff --git a/gcc/testsuite/gcc.dg/torture/pr101278.c b/gcc/testsuite/gcc.dg/torture/pr101278.c new file mode 100644 index 00000000000..1d25658f37d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr101278.c @@ -0,0 +1,21 @@ +/* { dg-do run } */ + +struct X { int counter; }; + +struct X __attribute__((noipa)) foo (struct X x) +{ + x.counter++; + if (x.counter == 5) + __builtin_exit (0); + return x; +} + +int +main () +{ + struct X x; + x.counter = 0; + for (int i = 0; i < 10; ++i) + x = foo (x); + __builtin_abort (); +} diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index c3939a6417f..98daa8ab24c 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -813,15 +813,11 @@ dse_classify_store (ao_ref *ref, gimple *stmt, break; } - /* We have visited ourselves already so ignore STMT for the - purpose of chaining. */ - if (use_stmt == stmt) - ; /* In simple cases we can look through PHI nodes, but we have to be careful with loops and with memory references containing operands that are also operands of PHI nodes. See gcc.c-torture/execute/20051110-*.c. */ - else if (gimple_code (use_stmt) == GIMPLE_PHI) + if (gimple_code (use_stmt) == GIMPLE_PHI) { /* If we already visited this PHI ignore it for further processing. */ @@ -861,6 +857,10 @@ dse_classify_store (ao_ref *ref, gimple *stmt, fail = true; break; } + /* We have visited ourselves already so ignore STMT for the + purpose of chaining. */ + else if (use_stmt == stmt) + ; /* If this is a store, remember it as we possibly need to walk the defs uses. */ else if (gimple_vdef (use_stmt)) -- 2.26.2