From patchwork Wed Oct 13 22:54:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 67747 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 8A108B70E9 for ; Thu, 14 Oct 2010 09:55:10 +1100 (EST) Received: (qmail 26588 invoked by alias); 13 Oct 2010 22:55:09 -0000 Received: (qmail 26580 invoked by uid 22791); 13 Oct 2010 22:55:07 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Oct 2010 22:54:53 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 47928CB02DB; Thu, 14 Oct 2010 00:54:51 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YGi3zH6+-v8N; Thu, 14 Oct 2010 00:54:51 +0200 (CEST) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 10883CB028D; Thu, 14 Oct 2010 00:54:51 +0200 (CEST) From: Eric Botcazou To: Ian Lance Taylor Subject: Re: PATCH RFC: Clean up TREE_THIS_NOTRAP, copy it to MEM_REF Date: Thu, 14 Oct 2010 00:54:03 +0200 User-Agent: KMail/1.9.9 Cc: gcc-patches@gcc.gnu.org References: <201010091042.55179.ebotcazou@adacore.com> In-Reply-To: <201010091042.55179.ebotcazou@adacore.com> MIME-Version: 1.0 Message-Id: <201010140054.04056.ebotcazou@adacore.com> 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 > The TREE_THIS_NOTRAP flag can get lost during inlining. We have the > attached hunks in our 4.5-based tree (to be adjusted to MEM_REF). The > sched-deps.c hunk is for the IA-64 because it abuses may_trap_p to detect > non-speculative instructions; when the TREE_THIS_NOTRAP is set, may_trap_p > returns false, although the instruction is still as speculative as without > it. Here is a formal submission (with the associated front-end changes). Bootstrapped/regtested on x86_64-suse-linux, OK for mainline? 2010-10-13 Eric Botcazou * sched-deps.c (sched_insn_is_legitimate_for_speculation): Invoke may_trap_or_fault_p instead of may_trap_p predicate. * tree.c (substitute_in_expr): Propagate the TREE_THIS_NOTRAP flag. (substitute_placeholder_in_expr): Likewise. * tree-inline.c (remap_gimple_op_r): Propagate the TREE_THIS_NOTRAP flag on MEM_REF nodes. (copy_tree_body_r): Propagate the TREE_READONLY and TREE_THIS_NOTRAP flags on INDIRECT_REF nodes. ada/ * gcc-interface/decl.c (gnat_to_gnu_entity) : Set TREE_THIS_NOTRAP on the INDIRECT_REF node built for the template. * gcc-interface/trans.c (Identifier_to_gnu): Set TREE_THIS_NOTRAP on the INDIRECT_REF node built for objects used by reference. * gcc-interface/utils2.c (build_binary_op): Add short-circuit for constant result. Set TREE_THIS_NOTRAP on ARRAY_REF and ARRAY_RANGE_REF. (gnat_stabilize_reference_1): Propagate the TREE_THIS_NOTRAP flag. Index: tree.c =================================================================== --- tree.c (revision 165254) +++ tree.c (working copy) @@ -3186,6 +3186,10 @@ substitute_in_expr (tree exp, tree f, tr } TREE_READONLY (new_tree) |= TREE_READONLY (exp); + + if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF) + TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp); + return new_tree; } @@ -3353,6 +3357,10 @@ substitute_placeholder_in_expr (tree exp } TREE_READONLY (new_tree) |= TREE_READONLY (exp); + + if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF) + TREE_THIS_NOTRAP (new_tree) |= TREE_THIS_NOTRAP (exp); + return new_tree; } Index: ada/gcc-interface/decl.c =================================================================== --- ada/gcc-interface/decl.c (revision 165416) +++ ada/gcc-interface/decl.c (working copy) @@ -1942,6 +1942,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit gnu_template_reference = build_unary_op (INDIRECT_REF, gnu_template_type, tem); TREE_READONLY (gnu_template_reference) = 1; + TREE_THIS_NOTRAP (gnu_template_reference) = 1; /* Now create the GCC type for each index and add the fields for that index to the template. */ Index: ada/gcc-interface/utils2.c =================================================================== --- ada/gcc-interface/utils2.c (revision 165416) +++ ada/gcc-interface/utils2.c (working copy) @@ -960,14 +960,19 @@ build_binary_op (enum tree_code op_code, result = fold_build2 (op_code, operation_type, left_operand, right_operand); + if (TREE_CONSTANT (result)) + ; + else if (op_code == ARRAY_REF || op_code == ARRAY_RANGE_REF) + { + TREE_THIS_NOTRAP (result) = 1; + if (TYPE_VOLATILE (operation_type)) + TREE_THIS_VOLATILE (result) = 1; + } + else + TREE_CONSTANT (result) + |= (TREE_CONSTANT (left_operand) && TREE_CONSTANT (right_operand)); + TREE_SIDE_EFFECTS (result) |= has_side_effects; - TREE_CONSTANT (result) - |= (TREE_CONSTANT (left_operand) & TREE_CONSTANT (right_operand) - && op_code != ARRAY_REF && op_code != ARRAY_RANGE_REF); - - if ((op_code == ARRAY_REF || op_code == ARRAY_RANGE_REF) - && TYPE_VOLATILE (operation_type)) - TREE_THIS_VOLATILE (result) = 1; /* If we are working with modular types, perform the MOD operation if something above hasn't eliminated the need for it. */ @@ -2347,6 +2352,9 @@ gnat_stabilize_reference_1 (tree e, bool TREE_SIDE_EFFECTS (result) |= TREE_SIDE_EFFECTS (e); TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e); + if (code == INDIRECT_REF || code == ARRAY_REF || code == ARRAY_RANGE_REF) + TREE_THIS_NOTRAP (result) = TREE_THIS_NOTRAP (e); + return result; } Index: ada/gcc-interface/trans.c =================================================================== --- ada/gcc-interface/trans.c (revision 165416) +++ ada/gcc-interface/trans.c (working copy) @@ -978,14 +978,22 @@ Identifier_to_gnu (Node_Id gnat_node, tr if (TREE_CODE (gnu_result) == PARM_DECL && DECL_BY_DOUBLE_REF_P (gnu_result)) - gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_result); + { + gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_result); + if (TREE_CODE (gnu_result) == INDIRECT_REF) + TREE_THIS_NOTRAP (gnu_result) = 1; + } if (TREE_CODE (gnu_result) == PARM_DECL && DECL_BY_COMPONENT_PTR_P (gnu_result)) - gnu_result - = build_unary_op (INDIRECT_REF, NULL_TREE, - convert (build_pointer_type (gnu_result_type), - gnu_result)); + { + gnu_result + = build_unary_op (INDIRECT_REF, NULL_TREE, + convert (build_pointer_type (gnu_result_type), + gnu_result)); + if (TREE_CODE (gnu_result) == INDIRECT_REF) + TREE_THIS_NOTRAP (gnu_result) = 1; + } /* If it's a renaming pointer and we are at the right binding level, we can reference the renamed object directly, since the renamed @@ -1003,7 +1011,11 @@ Identifier_to_gnu (Node_Id gnat_node, tr DECL_INITIAL (gnu_result)); else - gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_result); + { + gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_result); + if (TREE_CODE (gnu_result) == INDIRECT_REF) + TREE_THIS_NOTRAP (gnu_result) = 1; + } if (read_only) TREE_READONLY (gnu_result) = 1; Index: sched-deps.c =================================================================== --- sched-deps.c (revision 165254) +++ sched-deps.c (working copy) @@ -598,8 +598,8 @@ sched_insn_is_legitimate_for_speculation /* The following instructions, which depend on a speculatively scheduled instruction, cannot be speculatively scheduled along. */ { - if (may_trap_p (PATTERN (insn))) - /* If instruction might trap, it cannot be speculatively scheduled. + if (may_trap_or_fault_p (PATTERN (insn))) + /* If instruction might fault, it cannot be speculatively scheduled. For control speculation it's obvious why and for data speculation it's because the insn might get wrong input if speculation wasn't successful. */ Index: tree-inline.c =================================================================== --- tree-inline.c (revision 165254) +++ tree-inline.c (working copy) @@ -858,6 +858,7 @@ remap_gimple_op_r (tree *tp, int *walk_s *tp = fold_build2 (MEM_REF, TREE_TYPE (*tp), ptr, TREE_OPERAND (*tp, 1)); TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); + TREE_THIS_NOTRAP (*tp) = TREE_THIS_NOTRAP (old); } TREE_NO_WARNING (*tp) = TREE_NO_WARNING (old); *walk_subtrees = 0; @@ -1087,6 +1088,8 @@ copy_tree_body_r (tree *tp, int *walk_su *tp = build1 (INDIRECT_REF, type, new_tree); TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old); + TREE_READONLY (*tp) = TREE_READONLY (old); + TREE_THIS_NOTRAP (*tp) = TREE_THIS_NOTRAP (old); } } *walk_subtrees = 0;