From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 03F0C3851C07; Thu, 17 Sep 2020 14:24:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03F0C3851C07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600352692; bh=jaglIIVECFgRHO4iKEDuEeQPyXM1bA/F4m8Omgqgx1M=; h=From:To:Subject:Date:From; b=FZ31WaRgACTHcce4JuR8y1OvxtRxCUn++lznggpvETt4lHkOJCBe9L8vhS+JKn9aC yuW22AlXleq05vGnL1Zct2RKnuzCvyX4p5nTPz0dAMuPwFDBF7XLtYAwxuwQj2TYEk 7tu5kLjVQZ3VEfIS/XRkXoRCXGbNxQzhcTN/YmY0= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r8-10463] tree-dse: Fix mem* head trimming if call has lhs [PR94130] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-8 X-Git-Oldrev: 4910b2e4cfe25c95fef18cf54125b788c190cfb2 X-Git-Newrev: 9001bc36447e015283a5f1a0a924bd355f9d9df3 Message-Id: <20200917142452.03F0C3851C07@sourceware.org> Date: Thu, 17 Sep 2020 14:24:52 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 14:24:52 -0000 https://gcc.gnu.org/g:9001bc36447e015283a5f1a0a924bd355f9d9df3 commit r8-10463-g9001bc36447e015283a5f1a0a924bd355f9d9df3 Author: Jakub Jelinek Date: Thu Mar 12 09:34:00 2020 +0100 tree-dse: Fix mem* head trimming if call has lhs [PR94130] As the testcase shows, if DSE decides to head trim {mem{set,cpy,move},strncpy} and the call has lhs, it is incorrect to leave the lhs as is, because it will then point to the adjusted address (base + head_trim) instead of the original base. The following patch fixes that by dropping the lhs of the call and assigning lhs the original base in a following statement. 2020-03-12 Jakub Jelinek PR tree-optimization/94130 * tree-ssa-dse.c: Include gimplify.h. (increment_start_addr): If stmt has lhs, drop the lhs from call and set it after the call to the original value of the first argument. Formatting fixes. (decrement_count): Formatting fix. * gcc.c-torture/execute/pr94130.c: New test. (cherry picked from commit a545ffafa380fa958393e1dfbf7f5f8f129bc5cf) Diff: --- gcc/testsuite/gcc.c-torture/execute/pr94130.c | 16 ++++++++++++++++ gcc/tree-ssa-dse.c | 22 ++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.c-torture/execute/pr94130.c b/gcc/testsuite/gcc.c-torture/execute/pr94130.c new file mode 100644 index 00000000000..044e578d373 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr94130.c @@ -0,0 +1,16 @@ +/* PR tree-optimization/94130 */ + +int +main () +{ + int a[8]; + char *b = __builtin_memset (a, 0, sizeof (a)); + a[0] = 1; + a[1] = 2; + a[2] = 3; + if (b != (char *) a) + __builtin_abort (); + else + asm volatile ("" : : "g" (a) : "memory"); + return 0; +} diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index 9220fea7f2e..d6cb0ed6f4e 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-cfgcleanup.h" #include "params.h" #include "alias.h" +#include "gimplify.h" /* This file implements dead store elimination. @@ -373,29 +374,38 @@ decrement_count (gimple *stmt, int decrement) gcc_assert (TREE_CODE (*countp) == INTEGER_CST); *countp = wide_int_to_tree (TREE_TYPE (*countp), (TREE_INT_CST_LOW (*countp) - decrement)); - } static void increment_start_addr (gimple *stmt, tree *where, int increment) { + if (tree lhs = gimple_call_lhs (stmt)) + if (where == gimple_call_arg_ptr (stmt, 0)) + { + gassign *newop = gimple_build_assign (lhs, unshare_expr (*where)); + gimple_stmt_iterator gsi = gsi_for_stmt (stmt); + gsi_insert_after (&gsi, newop, GSI_SAME_STMT); + gimple_call_set_lhs (stmt, NULL_TREE); + update_stmt (stmt); + } + if (TREE_CODE (*where) == SSA_NAME) { tree tem = make_ssa_name (TREE_TYPE (*where)); gassign *newop - = gimple_build_assign (tem, POINTER_PLUS_EXPR, *where, + = gimple_build_assign (tem, POINTER_PLUS_EXPR, *where, build_int_cst (sizetype, increment)); gimple_stmt_iterator gsi = gsi_for_stmt (stmt); gsi_insert_before (&gsi, newop, GSI_SAME_STMT); *where = tem; - update_stmt (gsi_stmt (gsi)); + update_stmt (stmt); return; } *where = build_fold_addr_expr (fold_build2 (MEM_REF, char_type_node, - *where, - build_int_cst (ptr_type_node, - increment))); + *where, + build_int_cst (ptr_type_node, + increment))); } /* STMT is builtin call that writes bytes in bitmap ORIG, some bytes are dead