From patchwork Thu Oct 6 12:19:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1686809 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=oWvmfyll; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mjr9t4h2xz1yqk for ; Thu, 6 Oct 2022 23:20:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C19F13839DED for ; Thu, 6 Oct 2022 12:20:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C19F13839DED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665058813; bh=RUom7P2I+Ru5b0ufvIpIEe4eFRnqlTs9VvahetYx3f8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oWvmfyll92CLXn6FyBFBeWSVNzu6gx7yZk9ByqnakVEEBV5MdYCykVoyINWDbpIOl gh+SJMJzWBvM/PN1FDIza8EhfrbnuO9qD117RPA21ttn9N8Un4ka7J+c8YGk0/ZrSc ROfXytR/URcz/kgKVwEUBK+3XGIXJfpn/Zd/NULM= 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 [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 2C319383EC5C for ; Thu, 6 Oct 2022 12:19:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2C319383EC5C Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 1C4C91F8D4 for ; Thu, 6 Oct 2022 12:19:53 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (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 0BC4B2C16E for ; Thu, 6 Oct 2022 12:19:53 +0000 (UTC) Date: Thu, 6 Oct 2022 12:19:53 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/107115 - avoid bogus redundant store removal during RTL expansion User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20221006122013.C19F13839DED@sourceware.org> The following preserves the (premature) redundant store removal done in store_expr by appropriately guarding it with mems_same_for_tbaa_p. The testcase added needs scheduling disabled for now since there's a similar bug there still present. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/107115 * expr.cc (store_expr): Check mems_same_for_tbaa_p before eliding a seemingly redundant store. * gcc.dg/torture/pr107115.c: New testcase. --- gcc/expr.cc | 4 ++- gcc/testsuite/gcc.dg/torture/pr107115.c | 37 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr107115.c diff --git a/gcc/expr.cc b/gcc/expr.cc index 80bb1b8a4c5..ba627f176a7 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -6207,7 +6207,9 @@ store_expr (tree exp, rtx target, int call_param_p, if ((! rtx_equal_p (temp, target) || (temp != target && (side_effects_p (temp) - || side_effects_p (target)))) + || side_effects_p (target) + || (MEM_P (temp) + && !mems_same_for_tbaa_p (temp, target))))) && TREE_CODE (exp) != ERROR_MARK /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET, but TARGET is not valid memory reference, TEMP will differ diff --git a/gcc/testsuite/gcc.dg/torture/pr107115.c b/gcc/testsuite/gcc.dg/torture/pr107115.c new file mode 100644 index 00000000000..5f7b6ff01e1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr107115.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* PR/107115 */ +/* { dg-additional-options "-fno-schedule-insns -fno-schedule-insns2" } */ + +#include + +void test1(long *p1) +{ + p1[0] = 1; +} +long test2(long long *p2, int index1, int index2) +{ + p2[index1] = 2; + return p2[index2]; +} +long test3(long *p3, int index2, long value) +{ + p3[index2] = 3; + p3[index2] = value; + return p3[0]; +} +long test4(void *p4, int index1, int index2) +{ + test1(p4); + long temp = test2(p4, index1, index2); + return test3(p4, index2, temp); +} +long (*volatile vtest)(void *, int, int) = test4; +int main(void) +{ + void *pp = malloc(sizeof (long) + sizeof(long long)); + if (!pp) abort(); + long result = vtest(pp, 0, 0); + if (*(long *)pp != 2 || result != 2) + __builtin_abort (); + return 0; +}