From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11128 invoked by alias); 12 May 2017 12:04:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 11083 invoked by uid 89); 12 May 2017 12:04:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=sideeffects X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 May 2017 12:03:59 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C6FB9AD52 for ; Fri, 12 May 2017 12:03:59 +0000 (UTC) Date: Fri, 12 May 2017 12:49:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Properly fold stmts in PRE Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2017-05/txt/msg01029.txt.bz2 When Jeff did the DSE improvements I was reminded that PRE didn't fold calls properly (aka not in-place). This results in unfolded memory ops (not inlined or removed as do nothing for size zero). The following finally fixes that. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2017-05-12 Richard Biener * tree-ssa-sccvn.h (has_VN_INFO): Declare. * tree-ssa-pre.c (eliminate_dom_walker::before_dom_children): Fold all stmts not inplace. * g++.dg/tree-ssa/ssa-dse-2.C: Adjust. Index: gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C =================================================================== --- gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C (revision 247965) +++ gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C (working copy) @@ -54,6 +54,4 @@ fill_vec_av_set (av_set_t av) } /* { dg-final { scan-tree-dump-not "Trimming statement .head = -" "dse2" } } */ -/* { dg-final { scan-tree-dump "Deleted dead call: " "dse2" } } */ - - +/* { dg-final { scan-tree-dump-not "mem\[^\r\n\]*, 0\\);" "dse2" } } */ Index: gcc/tree-ssa-pre.c =================================================================== --- gcc/tree-ssa-pre.c (revision 247965) +++ gcc/tree-ssa-pre.c (working copy) @@ -4645,30 +4645,51 @@ eliminate_dom_walker::before_dom_childre && TREE_CODE (gimple_assign_rhs1 (stmt)) == ADDR_EXPR) recompute_tree_invariant_for_addr_expr (gimple_assign_rhs1 (stmt)); gimple *old_stmt = stmt; - if (is_gimple_call (stmt)) + gimple_stmt_iterator prev = gsi; + gsi_prev (&prev); + if (fold_stmt (&gsi)) { - /* ??? Only fold calls inplace for now, this may create new - SSA names which in turn will confuse free_scc_vn SSA name - release code. */ - fold_stmt_inplace (&gsi); - /* When changing a call into a noreturn call, cfg cleanup - is needed to fix up the noreturn call. */ - if (!was_noreturn && gimple_call_noreturn_p (stmt)) - el_to_fixup.safe_push (stmt); - } - else - { - fold_stmt (&gsi); - stmt = gsi_stmt (gsi); - if ((gimple_code (stmt) == GIMPLE_COND - && (gimple_cond_true_p (as_a (stmt)) - || gimple_cond_false_p (as_a (stmt)))) - || (gimple_code (stmt) == GIMPLE_SWITCH - && TREE_CODE (gimple_switch_index ( - as_a (stmt))) - == INTEGER_CST)) - el_todo |= TODO_cleanup_cfg; + /* fold_stmt may have created new stmts inbetween + the previous stmt and the folded stmt. Mark + all defs created there as varying to not confuse + the SCCVN machinery as we're using that even during + elimination. */ + if (gsi_end_p (prev)) + prev = gsi_start_bb (b); + else + gsi_next (&prev); + if (gsi_stmt (prev) != gsi_stmt (gsi)) + do + { + tree def; + ssa_op_iter dit; + FOR_EACH_SSA_TREE_OPERAND (def, gsi_stmt (prev), + dit, SSA_OP_ALL_DEFS) + /* As existing DEFs may move between stmts + we have to guard VN_INFO_GET. */ + if (! has_VN_INFO (def)) + VN_INFO_GET (def)->valnum = def; + if (gsi_stmt (prev) == gsi_stmt (gsi)) + break; + gsi_next (&prev); + } + while (1); } + stmt = gsi_stmt (gsi); + /* When changing a call into a noreturn call, cfg cleanup + is needed to fix up the noreturn call. */ + if (!was_noreturn + && is_gimple_call (stmt) && gimple_call_noreturn_p (stmt)) + el_to_fixup.safe_push (stmt); + /* When changing a condition or switch into one we know what + edge will be executed, schedule a cfg cleanup. */ + if ((gimple_code (stmt) == GIMPLE_COND + && (gimple_cond_true_p (as_a (stmt)) + || gimple_cond_false_p (as_a (stmt)))) + || (gimple_code (stmt) == GIMPLE_SWITCH + && TREE_CODE (gimple_switch_index + (as_a (stmt))) == INTEGER_CST)) + el_todo |= TODO_cleanup_cfg; /* If we removed EH side-effects from the statement, clean its EH information. */ if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)) Index: gcc/tree-ssa-sccvn.h =================================================================== --- gcc/tree-ssa-sccvn.h (revision 247965) +++ gcc/tree-ssa-sccvn.h (working copy) @@ -209,6 +209,7 @@ typedef struct vn_ssa_aux enum vn_lookup_kind { VN_NOWALK, VN_WALK, VN_WALKREWRITE }; /* Return the value numbering info for an SSA_NAME. */ +bool has_VN_INFO (tree); extern vn_ssa_aux_t VN_INFO (tree); extern vn_ssa_aux_t VN_INFO_GET (tree); tree vn_get_expr_for (tree);