From patchwork Mon Dec 13 17:50:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 75383 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 7A3A21007D4 for ; Tue, 14 Dec 2010 04:52:37 +1100 (EST) Received: (qmail 11394 invoked by alias); 13 Dec 2010 17:52:28 -0000 Received: (qmail 11375 invoked by uid 22791); 13 Dec 2010 17:52: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; Mon, 13 Dec 2010 17:52:19 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 44521CB027C for ; Mon, 13 Dec 2010 18:52:17 +0100 (CET) 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 ZQG-ovuTgytV for ; Mon, 13 Dec 2010 18:52:17 +0100 (CET) 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 0E749CB0278 for ; Mon, 13 Dec 2010 18:52:17 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Small tweak to 'for' loop translation Date: Mon, 13 Dec 2010 18:50:35 +0100 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201012131850.35981.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 This avoids generating useless entry tests for 'for' loops in some cases. Tested on i586-suse-linux, applied on the mainline. 2010-12-13 Eric Botcazou * gcc-interface/trans.c (can_be_lower_p): New predicate. (Loop_Statement_to_gnu): Do not generate the entry condition if we know that it will be true. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 167721) +++ gcc-interface/trans.c (working copy) @@ -2130,6 +2130,26 @@ can_equal_max_val_p (tree val, tree type return can_equal_min_or_max_val_p (val, type, !reverse); } +/* Return true if VAL1 can be lower than VAL2. */ + +static bool +can_be_lower_p (tree val1, tree val2) +{ + if (TREE_CODE (val1) == NOP_EXPR) + val1 = TYPE_MIN_VALUE (TREE_TYPE (TREE_OPERAND (val1, 0))); + + if (TREE_CODE (val1) != INTEGER_CST) + return true; + + if (TREE_CODE (val2) == NOP_EXPR) + val2 = TYPE_MAX_VALUE (TREE_TYPE (TREE_OPERAND (val2, 0))); + + if (TREE_CODE (val2) != INTEGER_CST) + return true; + + return tree_int_cst_lt (val1, val2); +} + /* Subroutine of gnat_to_gnu to translate gnat_node, an N_Loop_Statement, to a GCC tree, which is returned. */ @@ -2297,16 +2317,19 @@ Loop_Statement_to_gnu (Node_Id gnat_node LOOP_STMT_BOTTOM_COND_P (gnu_loop_stmt) = 1; /* If we use the BOTTOM_COND, we can turn the test into an inequality - test but we have to add an ENTRY_COND to protect the empty loop. */ + test but we may have to add ENTRY_COND to protect the empty loop. */ if (LOOP_STMT_BOTTOM_COND_P (gnu_loop_stmt)) { test_code = NE_EXPR; - gnu_cond_expr - = build3 (COND_EXPR, void_type_node, - build_binary_op (LE_EXPR, boolean_type_node, - gnu_low, gnu_high), - NULL_TREE, alloc_stmt_list ()); - set_expr_location_from_node (gnu_cond_expr, gnat_loop_spec); + if (can_be_lower_p (gnu_high, gnu_low)) + { + gnu_cond_expr + = build3 (COND_EXPR, void_type_node, + build_binary_op (LE_EXPR, boolean_type_node, + gnu_low, gnu_high), + NULL_TREE, alloc_stmt_list ()); + set_expr_location_from_node (gnu_cond_expr, gnat_loop_spec); + } } /* Open a new nesting level that will surround the loop to declare the