From patchwork Sat Sep 24 16:41:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 116229 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 BE903B6F81 for ; Sun, 25 Sep 2011 02:45:29 +1000 (EST) Received: (qmail 10333 invoked by alias); 24 Sep 2011 16:45:27 -0000 Received: (qmail 10323 invoked by uid 22791); 24 Sep 2011 16:45:25 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,TW_TM X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 24 Sep 2011 16:44:52 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 0C88ACB021A for ; Sat, 24 Sep 2011 18:44:53 +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 IkHMKdVVPJBx for ; Sat, 24 Sep 2011 18:44:42 +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 952E6CB01E8 for ; Sat, 24 Sep 2011 18:44:42 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] couple of small optimization tweaks Date: Sat, 24 Sep 2011 18:41:53 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Content-Disposition: inline Message-Id: <201109241841.53569.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 Hi, this is a couple of small tweaks to the GIMPLE optimizers aimed at helping vectorization in Ada. More changes will be needed, so no testcases yet. 1. pass_fold_builtins knows how to delete a call to __builtin_stack_restore that is the only real statement in a cleanup, i.e. to turn : .builtin_stack_restore (saved_stack.116_22); resx 1 into : GIMPLE_NOP resx 1 This is valid when the block has no outgoing edge. Then ehcleanup can in turn delete the cleanup as empty. The problem is that pass_fold_builtins runs very late in the game, so most of the optimizations, e.g. vectorization, are constrained by the EH structure, all the more so if -fnon-call-exceptions is enabled like in Ada. This happens as soon as you do dynamic stack allocation, because then you have a call to __builtin_stack_restore in the FINALLY part of a TRY-FINALLY structure, hence the cleanup. The first change enhances ehcleanup so as to remove this kind of cleanups on its own, without the need to wait for pass_fold_builtins. 2. The introduction of MEM_REF has disabled vectorization for parameters passed by reference in Ada. This used to work because dr_analyze_innermost was always building a pointer via build_fold_addr_expr; now, if the base is a MEM_REF, it can just take the first operand, which is a reference and not a pointer for a parameter passed by reference in Ada. And simple_iv, unlike other functions in tree-scalar-evolution.c, accepts only pointer types: type = TREE_TYPE (op); if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != POINTER_TYPE) return false; The second change makes simple_iv use the same test as the other functions in tree-scalar-evolution.c. Bootstrapped/regtested on x86_64-suse-linux, OK for mainline? 2011-09-24 Eric Botcazou * tree-eh.c (is_gimple_stack_restore): New predicate. (cleanup_empty_eh): Allow a call to __builtin_stack_restore if there is no outgoing edge. * tree-scalar-evolution.c (simple_iv): Accept all pointer and integral types. Index: tree-eh.c =================================================================== --- tree-eh.c (revision 179038) +++ tree-eh.c (working copy) @@ -3818,6 +3818,26 @@ infinite_empty_loop_p (edge e_first) return inf_loop; } +/* Return true if STMT is a call to __builtin_stack_restore. */ + +static bool +is_gimple_stack_restore (gimple stmt) +{ + tree callee; + + if (gimple_code (stmt) != GIMPLE_CALL) + return false; + + callee = gimple_call_fndecl (stmt); + + if (callee + && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL + && DECL_FUNCTION_CODE (callee) == BUILT_IN_STACK_RESTORE) + return true; + + return false; +} + /* Examine the block associated with LP to determine if it's an empty handler for its EH region. If so, attempt to redirect EH edges to an outer region. Return true the CFG was updated in any way. This @@ -3863,8 +3883,15 @@ cleanup_empty_eh (eh_landing_pad lp) return cleanup_empty_eh_unsplit (bb, e_out, lp); } - /* The block should consist only of a single RESX statement. */ + /* The block should consist only of a single RESX statement, modulo a + preceding call to __builtin_stack_restore if there is no outgoing + edge, since the call can be eliminated in this case. */ resx = gsi_stmt (gsi); + if (!e_out && is_gimple_stack_restore (resx)) + { + gsi_next (&gsi); + resx = gsi_stmt (gsi); + } if (!is_gimple_resx (resx)) return false; gcc_assert (gsi_one_before_end_p (gsi)); Index: tree-scalar-evolution.c =================================================================== --- tree-scalar-evolution.c (revision 179038) +++ tree-scalar-evolution.c (working copy) @@ -3172,8 +3172,8 @@ simple_iv (struct loop *wrto_loop, struc iv->no_overflow = false; type = TREE_TYPE (op); - if (TREE_CODE (type) != INTEGER_TYPE - && TREE_CODE (type) != POINTER_TYPE) + if (!POINTER_TYPE_P (type) + && !INTEGRAL_TYPE_P (type)) return false; ev = analyze_scalar_evolution_in_loop (wrto_loop, use_loop, op,