From patchwork Thu Sep 13 12:17:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 183618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A26632C0081 for ; Thu, 13 Sep 2012 22:20:51 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1348143651; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=Onn59+eQ+dIItNnjbdTz ibQpCwc=; b=ym+mG92rq2A1sM5cAN+vxzuhb2m8WD1aOYjGPzGen5iBR2L0ZZjE d825tsKN1snGrgAKsfeZefR3CrizNJzFUQy+dHuChEt7CipqblzV5xxjmuWAC8YK hBEShTSfb1nw4aND7ZrBxZNp/F6VmVNrS83OLCFZ9mtanryHuHpLnJc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=yAzD5MOIQgv/iwtTaWAD5/n4tGLD95BZTbKM5gXNmR7y8LyPE/v3N6o9gblp4t yIS+ujGRMzXiD84oG6jeVhRucC01Vg/qQGZc9YSvPagDktq05SWURavZKKwEbnwV r28XmqU/2ox7lt2kRngx7GfFnPyvFUI92/TRkIGoNAD0o=; Received: (qmail 26545 invoked by alias); 13 Sep 2012 12:20:43 -0000 Received: (qmail 26502 invoked by uid 22791); 13 Sep 2012 12:20:36 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, TW_TM X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Sep 2012 12:20:22 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 0E96EA3421 for ; Thu, 13 Sep 2012 14:20:21 +0200 (CEST) Date: Thu, 13 Sep 2012 14:17:30 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ADDR_EXPR handling in SCCVN and PRE Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This unifies the two code paths that try to figure out which VN handling routines are responsible for value-numbering. It also fixes ADDR_EXPR handling so that we handle those properly. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2012-09-13 Richard Guenther * tree-ssa-sccvn.h (enum vn_kind): New. (vn_get_stmt_kind): Likewise. * tree-ssa-sccvn.c (vn_get_stmt_kind): New function, adjust ADDR_EXPR handling. (visit_use): Use it. * tree-ssa-pre.c (compute_avail): Likewise, simplify further. * gcc.dg/tree-ssa/ssa-fre-37.c: New testcase. Index: gcc/tree-ssa-sccvn.h =================================================================== --- gcc/tree-ssa-sccvn.h (revision 191247) +++ gcc/tree-ssa-sccvn.h (working copy) @@ -121,6 +121,9 @@ typedef struct vn_constant_s tree constant; } *vn_constant_t; +enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI }; +enum vn_kind vn_get_stmt_kind (gimple); + /* Hash the constant CONSTANT with distinguishing type incompatible constants in the types_compatible_p sense. */ Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 191247) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -287,6 +287,63 @@ vn_get_expr_for (tree name) return expr; } +/* Return the vn_kind the expression computed by the stmt should be + associated with. */ + +enum vn_kind +vn_get_stmt_kind (gimple stmt) +{ + switch (gimple_code (stmt)) + { + case GIMPLE_CALL: + return VN_REFERENCE; + case GIMPLE_PHI: + return VN_PHI; + case GIMPLE_ASSIGN: + { + enum tree_code code = gimple_assign_rhs_code (stmt); + tree rhs1 = gimple_assign_rhs1 (stmt); + switch (get_gimple_rhs_class (code)) + { + case GIMPLE_UNARY_RHS: + case GIMPLE_BINARY_RHS: + case GIMPLE_TERNARY_RHS: + return VN_NARY; + case GIMPLE_SINGLE_RHS: + switch (TREE_CODE_CLASS (code)) + { + case tcc_reference: + /* VOP-less references can go through unary case. */ + if ((code == REALPART_EXPR + || code == IMAGPART_EXPR + || code == VIEW_CONVERT_EXPR + || code == BIT_FIELD_REF) + && TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME) + return VN_NARY; + + /* Fallthrough. */ + case tcc_declaration: + return VN_REFERENCE; + + case tcc_constant: + return VN_CONSTANT; + + default: + if (code == ADDR_EXPR) + return (is_gimple_min_invariant (rhs1) + ? VN_CONSTANT : VN_REFERENCE); + else if (code == CONSTRUCTOR) + return VN_NARY; + return VN_NONE; + } + default: + return VN_NONE; + } + } + default: + return VN_NONE; + } +} /* Free a phi operation structure VP. */ @@ -3364,44 +3421,13 @@ visit_use (tree use) } else { - switch (get_gimple_rhs_class (code)) + switch (vn_get_stmt_kind (stmt)) { - case GIMPLE_UNARY_RHS: - case GIMPLE_BINARY_RHS: - case GIMPLE_TERNARY_RHS: + case VN_NARY: changed = visit_nary_op (lhs, stmt); break; - case GIMPLE_SINGLE_RHS: - switch (TREE_CODE_CLASS (code)) - { - case tcc_reference: - /* VOP-less references can go through unary case. */ - if ((code == REALPART_EXPR - || code == IMAGPART_EXPR - || code == VIEW_CONVERT_EXPR - || code == BIT_FIELD_REF) - && TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME) - { - changed = visit_nary_op (lhs, stmt); - break; - } - /* Fallthrough. */ - case tcc_declaration: - changed = visit_reference_op_load (lhs, rhs1, stmt); - break; - default: - if (code == ADDR_EXPR) - { - changed = visit_nary_op (lhs, stmt); - break; - } - else if (code == CONSTRUCTOR) - { - changed = visit_nary_op (lhs, stmt); - break; - } - changed = defs_to_varying (stmt); - } + case VN_REFERENCE: + changed = visit_reference_op_load (lhs, rhs1, stmt); break; default: changed = defs_to_varying (stmt); Index: gcc/tree-ssa-pre.c =================================================================== --- gcc/tree-ssa-pre.c (revision 191247) +++ gcc/tree-ssa-pre.c (working copy) @@ -3922,21 +3922,22 @@ compute_avail (void) bitmap_value_insert_into_set (AVAIL_OUT (block), e); } - if (gimple_has_side_effects (stmt) || stmt_could_throw_p (stmt)) + if (gimple_has_side_effects (stmt) + || stmt_could_throw_p (stmt) + || is_gimple_debug (stmt)) continue; + FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE) + add_to_exp_gen (block, op); + switch (gimple_code (stmt)) { case GIMPLE_RETURN: - FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE) - add_to_exp_gen (block, op); continue; case GIMPLE_CALL: { vn_reference_t ref; - unsigned int i; - vn_reference_op_t vro; pre_expr result = NULL; VEC(vn_reference_op_s, heap) *ops = NULL; @@ -3952,18 +3953,6 @@ compute_avail (void) if (!ref) continue; - for (i = 0; VEC_iterate (vn_reference_op_s, - ref->operands, i, - vro); i++) - { - if (vro->op0 && TREE_CODE (vro->op0) == SSA_NAME) - add_to_exp_gen (block, vro->op0); - if (vro->op1 && TREE_CODE (vro->op1) == SSA_NAME) - add_to_exp_gen (block, vro->op1); - if (vro->op2 && TREE_CODE (vro->op2) == SSA_NAME) - add_to_exp_gen (block, vro->op2); - } - /* If the value of the call is not invalidated in this block until it is computed, add the expression to EXP_GEN. */ @@ -3988,28 +3977,19 @@ compute_avail (void) case GIMPLE_ASSIGN: { pre_expr result = NULL; - switch (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt))) + switch (vn_get_stmt_kind (stmt)) { - case tcc_unary: - case tcc_binary: - case tcc_comparison: + case VN_NARY: { vn_nary_op_t nary; - unsigned int i; - vn_nary_op_lookup_pieces (gimple_num_ops (stmt) - 1, gimple_assign_rhs_code (stmt), gimple_expr_type (stmt), gimple_assign_rhs1_ptr (stmt), &nary); - if (!nary) continue; - for (i = 0; i < nary->length; i++) - if (TREE_CODE (nary->op[i]) == SSA_NAME) - add_to_exp_gen (block, nary->op[i]); - /* If the NARY traps and there was a preceding point in the block that might not return avoid adding the nary to EXP_GEN. */ @@ -4024,31 +4004,15 @@ compute_avail (void) break; } - case tcc_declaration: - case tcc_reference: + case VN_REFERENCE: { vn_reference_t ref; - unsigned int i; - vn_reference_op_t vro; - vn_reference_lookup (gimple_assign_rhs1 (stmt), gimple_vuse (stmt), VN_WALK, &ref); if (!ref) continue; - for (i = 0; VEC_iterate (vn_reference_op_s, - ref->operands, i, - vro); i++) - { - if (vro->op0 && TREE_CODE (vro->op0) == SSA_NAME) - add_to_exp_gen (block, vro->op0); - if (vro->op1 && TREE_CODE (vro->op1) == SSA_NAME) - add_to_exp_gen (block, vro->op1); - if (vro->op2 && TREE_CODE (vro->op2) == SSA_NAME) - add_to_exp_gen (block, vro->op2); - } - /* If the value of the reference is not invalidated in this block until it is computed, add the expression to EXP_GEN. */ @@ -4082,18 +4046,12 @@ compute_avail (void) } default: - /* For any other statement that we don't - recognize, simply add all referenced - SSA_NAMEs to EXP_GEN. */ - FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE) - add_to_exp_gen (block, op); continue; } get_or_alloc_expression_id (result); add_to_value (get_expr_value_id (result), result); bitmap_value_insert_into_set (EXP_GEN (block), result); - continue; } default: Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-37.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-37.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-37.c (working copy) @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-fre1" } */ + +int a[256]; +int *b, *c; +void foo (int i, int j) +{ + b = &a[i+j]; + c = &a[i+j]; +} + +/* We should remove the redundant address computation. */ + +/* { dg-final { scan-tree-dump-times " = &a" 1 "fre1" } } */ +/* { dg-final { cleanup-tree-dump "fre1" } } */