From patchwork Tue Jun 3 07:23:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 355197 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 4EF5E1400A4 for ; Tue, 3 Jun 2014 17:24:01 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Kv/k9UDxFNO+QU1ejSztL/nDYgXbt/cOu+tRGdynL6bSeoN2EJqSu kTiKRikujAmfT1EKXf1owENJrkUnXwRI/ZssbjZAMEoHxn1Y+w76edC33Oe3cCJG mex2OmB6THqGah57PqeglWs11NozuF8lOYuzcGMKwxi0NUUFeXFcU4= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=HwK2Ops78P+gC84SXZsQMV50IA0=; b=vMDPk39qEWn5e8ySmiHr e1LUjRqru+MxqbC9IV3wi05NMd4d+vzdJ1WgfcsM/rMikj4iBQEgUhfb0JEX5U1G yZyyWdmbevV02nwa7xer6yG6o62+BvJ5B2J235wqAivB/6clZcHhm+oFygJWjW+n 0vG8l44zSEZdUUgB1UT1aJA= Received: (qmail 16434 invoked by alias); 3 Jun 2014 07:23:55 -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 16424 invoked by uid 89); 3 Jun 2014 07:23:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f53.google.com Received: from mail-pb0-f53.google.com (HELO mail-pb0-f53.google.com) (209.85.160.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 03 Jun 2014 07:23:53 +0000 Received: by mail-pb0-f53.google.com with SMTP id md12so5125493pbc.12 for ; Tue, 03 Jun 2014 00:23:51 -0700 (PDT) X-Received: by 10.68.220.103 with SMTP id pv7mr47470812pbc.17.1401780231386; Tue, 03 Jun 2014 00:23:51 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by mx.google.com with ESMTPSA id gr10sm24174321pbc.84.2014.06.03.00.23.49 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Jun 2014 00:23:50 -0700 (PDT) Date: Tue, 3 Jun 2014 11:23:40 +0400 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, Pointer Bounds Checker 25/x] DCE Message-ID: <20140603072340.GC20877@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, This patch adjusts alloc-free removal algorithm in DCE to take into account BUILT_IN_CHKP_BNDRET call returning bounds of allocated memory. Bootstrapped and tested on linux-x86_64. Thanks, Ilya --- gcc/ 2014-06-03 Ilya Enkovich * tree-ssa-dce.c: Include target.h. (propagate_necessity): For free call fed by alloc check bounds are also provided by the same alloc. (eliminate_unnecessary_stmts): Handle BUILT_IN_CHKP_BNDRET used by free calls. diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index 13a71ce..59a0b71 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -73,6 +73,7 @@ along with GCC; see the file COPYING3. If not see #include "flags.h" #include "cfgloop.h" #include "tree-scalar-evolution.h" +#include "target.h" static struct stmt_stats { @@ -778,7 +779,23 @@ propagate_necessity (bool aggressive) && DECL_BUILT_IN_CLASS (def_callee) == BUILT_IN_NORMAL && (DECL_FUNCTION_CODE (def_callee) == BUILT_IN_MALLOC || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_CALLOC)) - continue; + { + tree retfndecl + = targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDRET); + gimple bounds_def_stmt; + tree bounds; + + /* For instrumented calls we should also check used + bounds are returned by the same allocation call. */ + if (!gimple_call_with_bounds_p (stmt) + || ((bounds = gimple_call_arg (stmt, 1)) + && TREE_CODE (bounds) == SSA_NAME + && (bounds_def_stmt = SSA_NAME_DEF_STMT (bounds)) + && is_gimple_call (bounds_def_stmt) + && gimple_call_fndecl (bounds_def_stmt) == retfndecl + && gimple_call_arg (bounds_def_stmt, 0) == ptr)) + continue; + } } FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE) @@ -1204,6 +1221,23 @@ eliminate_unnecessary_stmts (void) && !gimple_plf (def_stmt, STMT_NECESSARY)) gimple_set_plf (stmt, STMT_NECESSARY, false); } + /* We did not propagate necessity for free calls fed + by allocation function to allow unnecessary + alloc-free sequence elimination. For instrumented + calls it also means we did not mark bounds producer + as necessary and it is time to do it in case free + call is not removed. */ + if (gimple_call_with_bounds_p (stmt)) + { + gimple bounds_def_stmt; + tree bounds = gimple_call_arg (stmt, 1); + gcc_assert (TREE_CODE (bounds) == SSA_NAME); + bounds_def_stmt = SSA_NAME_DEF_STMT (bounds); + if (bounds_def_stmt + && !gimple_plf (bounds_def_stmt, STMT_NECESSARY)) + gimple_set_plf (bounds_def_stmt, STMT_NECESSARY, + gimple_plf (stmt, STMT_NECESSARY)); + } } /* If GSI is not necessary then remove it. */ @@ -1216,6 +1250,7 @@ eliminate_unnecessary_stmts (void) else if (is_gimple_call (stmt)) { tree name = gimple_call_lhs (stmt); + tree retfn = targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDRET); notice_special_calls (stmt); @@ -1233,7 +1268,9 @@ eliminate_unnecessary_stmts (void) && DECL_FUNCTION_CODE (call) != BUILT_IN_CALLOC && DECL_FUNCTION_CODE (call) != BUILT_IN_ALLOCA && (DECL_FUNCTION_CODE (call) - != BUILT_IN_ALLOCA_WITH_ALIGN)))) + != BUILT_IN_ALLOCA_WITH_ALIGN))) + /* Avoid doing so for bndret calls for the same reason. */ + && (!retfn || gimple_call_fndecl (stmt) != retfn)) { something_changed = true; if (dump_file && (dump_flags & TDF_DETAILS))