From patchwork Wed Oct 8 19:08:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 397695 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 7AD921400D6 for ; Thu, 9 Oct 2014 06:09:14 +1100 (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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=oFtf49fiFirkeKskDsCAAIJROBgAIEqoPo4rTKQ+Lg9kWk+Q3B CQGZ3SS3kq1IrdJbSrNjoC/ixzMVqYFxKf7Z/VXEobXmCrlv52p0p2VxVVrYWAbq z4ObWigIziYdWwnADq+spgMfHVGSkVYPljR9tK2bAIJpsm2pcYSRjiN2E= 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:cc:subject:message-id:mime-version:content-type; s= default; bh=/zPVvH+ROl7e1FyVmkZUzf4mI24=; b=KiHvCbSWQEfv5OtBcp27 NmPdkX8csH5tN2zlXuhSOICpr3bF6bn9JoOmBKHv3UEO/LWvxOW4A4ClEk3U1Mpj LwUNZDeaamqIYRVhRCW0xHHOGpPILNMmI48pJ2tDN0haTs8WH1NpI7wwy9Dbx3hC sCVHzGyZtX/sUu1rjK1Zy4Q= Received: (qmail 6873 invoked by alias); 8 Oct 2014 19:09:07 -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 6863 invoked by uid 89); 8 Oct 2014 19:09:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f169.google.com Received: from mail-pd0-f169.google.com (HELO mail-pd0-f169.google.com) (209.85.192.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 08 Oct 2014 19:09:05 +0000 Received: by mail-pd0-f169.google.com with SMTP id w10so7404102pde.0 for ; Wed, 08 Oct 2014 12:09:03 -0700 (PDT) X-Received: by 10.70.119.105 with SMTP id kt9mr13289531pdb.7.1412795343355; Wed, 08 Oct 2014 12:09:03 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by mx.google.com with ESMTPSA id ra4sm704180pab.33.2014.10.08.12.09.01 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Oct 2014 12:09:02 -0700 (PDT) Date: Wed, 8 Oct 2014 23:08:57 +0400 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Cc: Jeff Law Subject: [PATCH, Pointer Bounds Checker 14/x] Passes [8/n] Remove useless builtin calls Message-ID: <20141008190857.GH13454@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 adds removal of user calls to chkp builtins which become useless after instrumentation. Thanks, Ilya --- 2014-10-08 Ilya Enkovich * tree-chkp.c (chkp_remove_useless_builtins): New. (chkp_execute): Remove useless calls to Pointer Bounds Checker builtins. diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 5443950..b424af8 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -3805,6 +3805,49 @@ chkp_instrument_function (void) } } +/* Find init/null/copy_ptr_bounds calls and replace them + with assignments. It should allow better code + optimization. */ + +static void +chkp_remove_useless_builtins () +{ + basic_block bb, next; + gimple_stmt_iterator gsi; + + bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb; + do + { + next = bb->next_bb; + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple stmt = gsi_stmt (gsi); + tree fndecl; + enum built_in_function fcode; + + /* Find builtins returning first arg and replace + them with assignments. */ + if (gimple_code (stmt) == GIMPLE_CALL + && (fndecl = gimple_call_fndecl (stmt)) + && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL + && (fcode = DECL_FUNCTION_CODE (fndecl)) + && (fcode == BUILT_IN_CHKP_INIT_PTR_BOUNDS + || fcode == BUILT_IN_CHKP_NULL_PTR_BOUNDS + || fcode == BUILT_IN_CHKP_COPY_PTR_BOUNDS + || fcode == BUILT_IN_CHKP_SET_PTR_BOUNDS)) + { + tree res = gimple_call_arg (stmt, 0); + if (!update_call_from_tree (&gsi, res)) + gimplify_and_update_call_from_tree (&gsi, res); + stmt = gsi_stmt (gsi); + update_stmt (stmt); + } + } + bb = next; + } + while (bb); +} + /* Initialize pass. */ static void chkp_init (void) @@ -3872,6 +3915,8 @@ chkp_execute (void) chkp_instrument_function (); + chkp_remove_useless_builtins (); + chkp_function_mark_instrumented (cfun->decl); chkp_fix_cfg ();