From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id BC7733882150; Thu, 6 Oct 2022 12:20:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC7733882150 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665058815; bh=4+EXUgQFTLSG9YQX18+QS/1TRj0QgieEGdv5Nucj5vw=; h=From:To:Subject:Date:From; b=ukEh0wNMkmUknDRstBLpvJDgeI+zQh7vV8A5tEqxBNhXelO2ZNVOd19exgsqKemKX WIGavJBCmXH2SvCUNKzZMIBLutxTvw8Jj1+59MpjgA/T6tDipcIzDUYJ4d2dyZp4Eh ffDUYu4KUZIqTVppv+wlcGxkhiVWC9EMoo6Dcxlk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3131] middle-end/107115 - avoid bogus redundant store removal during RTL expansion X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 33b93ac3f2fb68a2da0d42fd692fe59533f7a84f X-Git-Newrev: 0af8d957d5911fc7659b4174cfc2213289bbed23 Message-Id: <20221006122015.BC7733882150@sourceware.org> Date: Thu, 6 Oct 2022 12:20:15 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0af8d957d5911fc7659b4174cfc2213289bbed23 commit r13-3131-g0af8d957d5911fc7659b4174cfc2213289bbed23 Author: Richard Biener Date: Thu Oct 6 11:48:03 2022 +0200 middle-end/107115 - avoid bogus redundant store removal during RTL expansion 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. 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. Diff: --- gcc/expr.cc | 4 +++- gcc/testsuite/gcc.dg/torture/pr107115.c | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) 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; +}