From patchwork Mon Mar 21 11:19:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 87743 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 4727BB6F2B for ; Mon, 21 Mar 2011 22:24:31 +1100 (EST) Received: (qmail 5630 invoked by alias); 21 Mar 2011 11:24:22 -0000 Received: (qmail 5621 invoked by uid 22791); 21 Mar 2011 11:24:21 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, LOTS_OF_MONEY, TW_OV, 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, 21 Mar 2011 11:24:11 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 8FFDCCB0260 for ; Mon, 21 Mar 2011 12:24:09 +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 hmwq93+K6Ly5 for ; Mon, 21 Mar 2011 12:24:06 +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 2AB15CB0224 for ; Mon, 21 Mar 2011 12:24:06 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Couple of tweaks to the gimplifier Date: Mon, 21 Mar 2011 12:19:29 +0100 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201103211219.30008.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, the attached patch makes a couple of tweaks to the gimplifier in order to help Ada, but I think that they are of general usefulness: 1) Set TREE_THIS_NOTRAP on the INDIRECT_REF built for VLA decls. This is correct since stack memory isn't considered as trapping in the IL. 2) Improve gimplification of complex conditions in COND_EXPR. They are naturally generated by the Ada compiler and the patch avoids emitting redundant branches in GIMPLE, visible at -O0 for the testcase: procedure P (B : Boolean; S1, S2 : String) is begin if B and then S1 & S2 = "toto" then raise Program_Error; end if; end; @@ -158,21 +158,12 @@ movl %r12d, %eax subl %ebx, %eax cmpl $3, %eax - jne .L33 + jne .L18 .loc 1 3 0 discriminator 1 movq -40(%rbp), %rax movl (%rax), %eax cmpl $1869901684, %eax - jne .L33 - .loc 1 3 0 discriminator 2 - movl $1, %eax - jmp .L34 -.L33: - movl $0, %eax -.L34: - .loc 1 3 0 discriminator 3 - testb %al, %al - je .L18 + jne .L18 .loc 1 4 0 is_stmt 1 movl $4, %esi movl $.LC0, %edi Bootstrapped/regtested on x86_64-suse-linux, OK for the mainline? 2011-03-21 Eric Botcazou * gimplify.c (gimplify_vla_decl): Set TREE_THIS_NOTRAP flag. (gimplify_cond_expr): Gimplify COMPOUND_EXPR conditions. Index: gimplify.c =================================================================== --- gimplify.c (revision 171044) +++ gimplify.c (working copy) @@ -1322,6 +1322,7 @@ gimplify_vla_decl (tree decl, gimple_seq addr = create_tmp_var (ptr_type, get_name (decl)); DECL_IGNORED_P (addr) = 0; t = build_fold_indirect_ref (addr); + TREE_THIS_NOTRAP (t) = 1; SET_DECL_VALUE_EXPR (decl, t); DECL_HAS_VALUE_EXPR_P (decl) = 1; @@ -2981,6 +2982,11 @@ gimplify_cond_expr (tree *expr_p, gimple return GS_ALL_DONE; } + /* Remove any COMPOUND_EXPR so the following cases will be caught. */ + STRIP_TYPE_NOPS (TREE_OPERAND (expr, 0)); + if (TREE_CODE (TREE_OPERAND (expr, 0)) == COMPOUND_EXPR) + gimplify_compound_expr (&TREE_OPERAND (expr, 0), pre_p, true); + /* Make sure the condition has BOOLEAN_TYPE. */ TREE_OPERAND (expr, 0) = gimple_boolify (TREE_OPERAND (expr, 0));