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: 1782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp282791wrs; Thu, 6 Oct 2022 05:20:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6o+J0gGydp+w+w7PEmdsB1CT5PM6oRQbGyJn8dIb+Vtih66Nbcm+ODvghgYmq684VAPDu7 X-Received: by 2002:aa7:c642:0:b0:458:e065:105b with SMTP id z2-20020aa7c642000000b00458e065105bmr4312276edr.354.1665058843516; Thu, 06 Oct 2022 05:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665058843; cv=none; d=google.com; s=arc-20160816; b=mvcqvYH41jZaSPqqY74ImE0xxVPX+vpTyN8AM8erDjf4C1ABRiTtlZFNhfitl44rdI Uce5Fh9WyccrtGjVlswEMTrdJq8UFC4KJ9z/xdCyQk6i7zW9uiwMaNYimfSkH1aZWcWY lAbkDU/wO5vsjAUSJtOicpysDMWn6dhVcfwuk6quig2SOgzTBHyUn6ENMxJVf2e9Cg7d ++Zr5wUYoPRd/wV/iLD4WkTc1g5u5qeLQiK+SMgMNDa9rAExXFM4lb76qYdxUXX0UmB+ T4v3C93loEZ+7sn2xd8JbcwlFWlouVx+1hqqBEs+IvUcCIYvVuBHoGu+oQpAY0gshLQy sB1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=RUom7P2I+Ru5b0ufvIpIEe4eFRnqlTs9VvahetYx3f8=; b=BRc0JuY9NuMp01C9X+Ic/bPILuVpqyCG9CBh2rbNU9cfcegKFZcQL0oFlmNrrvTMQc BlJj91kqc0uCaRDMMP+z/bpmn2DN3YBrr6VtNo+uiHZ6BP4U/xA+WHcfpoMuQeBltypY ZdGNgqbjThjBCXB1IT7PwOlS71EATIJvJPsBwTvrVBTh9BzOio0sWlKC3KiUtnOoMR8S 6rjXHzlkWD/NkLkADVgbE9RUYq8NTjUlSYCdB7gsuTefR3w2X6T5CX2FPwkXhBaVsGw/ LNHeND6JsC+sVnJs2sWGLJDrqGnyJpktczvHO1dzGGlo31k0UXO7c9UuPWxs7KqWCol9 hCEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hbjVXllT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id wu11-20020a170906eecb00b00774195db4e7si1419759ejb.117.2022.10.06.05.20.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 05:20:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hbjVXllT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 48AAF3839DFC for ; Thu, 6 Oct 2022 12:20:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48AAF3839DFC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665058837; bh=RUom7P2I+Ru5b0ufvIpIEe4eFRnqlTs9VvahetYx3f8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hbjVXllTFe9Y6/Sy65MPnh42SNg0F/UZkeDW9RyRtAp12mmOJZxkC779Rc0Do09AW uDHqzExlbspGrrnEy+EPkvyWtK8fso9ZqUwHtHJZ21p8CgB4gCiBOy3wub+wCvjlst JbBtLYJ44e8D6yuqE7NGIFi1gZ+gsgaSzZZCY2oM= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20221006122037.48AAF3839DFC@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745940741501159902?= X-GMAIL-MSGID: =?utf-8?q?1745940741501159902?= 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; +}