From patchwork Wed Jun 15 11:36:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 635821 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rV4HG0RKNz9t17 for ; Wed, 15 Jun 2016 21:36:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=k5shSkNs; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=fJVFbVPddB6LL/e+5 yOxU4oSNBbPA5HGlBTglUKqjhDVwTMklK5TKRFO51imbyzmymGdy2gk2SZ7ji7kh Zlq3+6E9z1ENLMtZvXfyFildCisipyzxX8ZMTa4v3IYZkBolKjx8g67B6fGw1J9p dW+WBn/8mDqPMKtAEnHcV7QBd8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=eD0gUTOrdgxx0l6xQihDZq1 nLB8=; b=k5shSkNsN9KVjm1hSBSgRoqD76TtqriIOJQMEDmogTJN2BhOrw5zC2f hsLtOf2uOqlHqQO6hdNAxclnpV1AbAy2L2rRXSVNWYOBBg4jwHQGxsnR9BDuf5l7 vwfO+N1oQym/JEhDurOnFjBAX+VTnGaWIItNqH9bD+onrJZbCi7g= Received: (qmail 88279 invoked by alias); 15 Jun 2016 11:36:48 -0000 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 Received: (qmail 88248 invoked by uid 89); 15 Jun 2016 11:36:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=cond2, Properly X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Wed, 15 Jun 2016 11:36:36 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8F342AC5B; Wed, 15 Jun 2016 11:36:33 +0000 (UTC) Subject: Re: [PATCH] Fix code emission for FAIL_ALLOC predictor To: gcc-patches@gcc.gnu.org References: <47866b03-3c9e-aec5-79d4-693371e0b5e9@suse.cz> Cc: Jan Hubicka From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <795d2de2-3d43-df68-1f82-9616beda9acf@suse.cz> Date: Wed, 15 Jun 2016 13:36:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <47866b03-3c9e-aec5-79d4-693371e0b5e9@suse.cz> X-IsSubscribed: yes Adding missing patch. Martin From 35ba97e0139d955c04e67ca157f8899bbb468bf1 Mon Sep 17 00:00:00 2001 From: marxin Date: Thu, 9 Jun 2016 17:51:38 +0200 Subject: [PATCH] Fix code emission for FAIL_ALLOC predictor gcc/ChangeLog: 2016-06-13 Martin Liska * predict.def: Define a new predictor. gcc/fortran/ChangeLog: 2016-06-13 Martin Liska * trans-array.c (gfc_array_allocate): Do not generate expect stmt. * trans.c (gfc_allocate_using_malloc): Properly set FAIL_ALLOC predictor for malloc return value. (gfc_allocate_allocatable): Use REALLOC predictor instead of FAIL_ALLOC. (gfc_deallocate_with_status): Likewise. --- gcc/fortran/trans-array.c | 2 +- gcc/fortran/trans.c | 10 ++++------ gcc/predict.def | 15 +++++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 403ce3a..e95c8dd 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -5553,7 +5553,7 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg, build_int_cst (TREE_TYPE (status), 0)); gfc_add_expr_to_block (&se->pre, fold_build3_loc (input_location, COND_EXPR, void_type_node, - gfc_likely (cond, PRED_FORTRAN_FAIL_ALLOC), + cond, set_descriptor, build_empty_stmt (input_location))); } diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c index c6688d3..d6b4a56 100644 --- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -672,9 +672,6 @@ gfc_allocate_using_malloc (stmtblock_t * block, tree pointer, gfc_start_block (&on_error); if (status != NULL_TREE) { - gfc_add_expr_to_block (&on_error, - build_predict_expr (PRED_FORTRAN_FAIL_ALLOC, - NOT_TAKEN)); tmp = fold_build2_loc (input_location, MODIFY_EXPR, status_type, status, build_int_cst (status_type, LIBERROR_ALLOCATION)); gfc_add_expr_to_block (&on_error, tmp); @@ -693,7 +690,8 @@ gfc_allocate_using_malloc (stmtblock_t * block, tree pointer, boolean_type_node, pointer, build_int_cst (prvoid_type_node, 0)); tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node, - error_cond, gfc_finish_block (&on_error), + gfc_unlikely (error_cond, PRED_FORTRAN_FAIL_ALLOC), + gfc_finish_block (&on_error), build_empty_stmt (input_location)); gfc_add_expr_to_block (block, tmp); @@ -796,7 +794,7 @@ gfc_allocate_allocatable (stmtblock_t * block, tree mem, tree size, tree token, null_mem = gfc_unlikely (fold_build2_loc (input_location, NE_EXPR, boolean_type_node, mem, build_int_cst (type, 0)), - PRED_FORTRAN_FAIL_ALLOC); + PRED_FORTRAN_REALLOC); /* If mem is NULL, we call gfc_allocate_using_malloc or gfc_allocate_using_lib. */ @@ -1385,7 +1383,7 @@ gfc_deallocate_with_status (tree pointer, tree status, tree errmsg, cond2 = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, stat, build_zero_cst (TREE_TYPE (stat))); tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node, - gfc_unlikely (cond2, PRED_FORTRAN_FAIL_ALLOC), + gfc_unlikely (cond2, PRED_FORTRAN_REALLOC), tmp, build_empty_stmt (input_location)); gfc_add_expr_to_block (&non_null, tmp); } diff --git a/gcc/predict.def b/gcc/predict.def index c0a3f36..da4f9ab 100644 --- a/gcc/predict.def +++ b/gcc/predict.def @@ -163,12 +163,15 @@ DEF_PREDICTOR (PRED_FORTRAN_OVERFLOW, "overflow", PROB_ALWAYS, PRED_FLAG_FIRST_MATCH) /* Branch leading to a failure status are unlikely. This can occur for out - of memory or when trying to allocate an already allocated allocated or - deallocating an already deallocated allocatable. This predictor only - occurs when the user explicitly asked for a return status. By default, - the code aborts, which is handled via PRED_NORETURN. - FIXME: the hitrate really ought to be close to 100%. */ -DEF_PREDICTOR (PRED_FORTRAN_FAIL_ALLOC, "fail alloc", HITRATE (62), 0) + of memory. This predictor only occurs when the user explicitly asked + for a return status. By default, the code aborts, + which is handled via PRED_NORETURN. */ +DEF_PREDICTOR (PRED_FORTRAN_FAIL_ALLOC, "fail alloc", PROB_VERY_LIKELY, 0) + +/* Predictor is used for an allocation of an already allocated memory or + deallocating an already deallocated allocatable. */ +DEF_PREDICTOR (PRED_FORTRAN_REALLOC, "repeated allocation/deallocation", \ + PROB_LIKELY, 0) /* Branch leading to an I/O failure status are unlikely. This predictor is used for I/O failures such as for invalid unit numbers. This predictor -- 2.8.3