From patchwork Mon Jul 21 17:06:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Mi X-Patchwork-Id: 372168 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 2F8D314011D for ; Tue, 22 Jul 2014 03:06:39 +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 :mime-version:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=XOYME1XGM+oh6yzcLi2V2ywt4BhdnorQUAS6Ot0HcKW gDTmM4iQbZzz75xu2DV//OLBwJcLO8DdS+jiSKdamtnsqnlZ+E45HhVeiSzq6ZTW oO5LwCzmBrYR76hztsvpQVSfKOi9zowMpk8xObutLUrrBSCYd7atypYWnGhTvbIY = 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 :mime-version:date:message-id:subject:from:to:cc:content-type; s=default; bh=uwdG7R0IDTCuE6OpVK1i8eDF9+I=; b=S9aWiIxC1CiAxOYTz zp8mB4Ns8Lx2zYkRxqwI57PuLGAyKOWVRTm/yatXFJjuJLGt3Z84lQBqAKhdAz06 ijNOxzz8qXjXnCHkFdBudy1d3aGI47huthPYcaj7doINmdviTTNeBmUR3go7/Eho 5nUPBk51CHNe66n7GkEzXsfzUc= Received: (qmail 728 invoked by alias); 21 Jul 2014 17:06:32 -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 702 invoked by uid 89); 21 Jul 2014 17:06:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-oa0-f49.google.com Received: from mail-oa0-f49.google.com (HELO mail-oa0-f49.google.com) (209.85.219.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 21 Jul 2014 17:06:29 +0000 Received: by mail-oa0-f49.google.com with SMTP id eb12so7807298oac.36 for ; Mon, 21 Jul 2014 10:06:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=piCjPWdQm/G3n0r9x8b1f/8zDfwAFpTVaGh1JvZsagk=; b=J/UCkIcSoDB1ZxgDEixZBS/Mv0ULoMN2c9XZ/VAb8FWhmNs+Kan3/Any6iNAQ2ZBz2 G8PY7dr3kOvlAg49SwyPXLIMgBaGI0YOOLvQyTqRrAH6RTNRlXPpIqQsXKga9VOnJTVQ ggUhAM/pSllxNT7mljq+OONr8cYX2q++nRLxVUwlaQnozpCWS4qJRsRe8ZgiEGbmQj4G vdElhJQEulM55rKThTyQL+2u9DdzjaryhlFX5dDThmUUaU8bTILTXqgIhWmGPYLh/153 rwnUgddSCxIcwR0usKz/RKXI8oce+343tOK51+d6Icrk2MkZR2N7Rar7a9FyF0G9ceTw Q9jg== X-Gm-Message-State: ALoCoQk1kCybopmKvZsebx+zzpx4y02sZ2y6oSpWwb2n0+VnrUvbaUBOM+XnosEpwI/CdoY665/k MIME-Version: 1.0 X-Received: by 10.60.59.130 with SMTP id z2mr39423849oeq.4.1405962387088; Mon, 21 Jul 2014 10:06:27 -0700 (PDT) Received: by 10.76.152.199 with HTTP; Mon, 21 Jul 2014 10:06:26 -0700 (PDT) Date: Mon, 21 Jul 2014 10:06:26 -0700 Message-ID: Subject: [PATCH, PR61776] verify_flow_info failed: control flow in the middle of basic block with -fprofile-generate From: Wei Mi To: GCC Patches Cc: Richard Biener , Jan Hubicka , David Li Hi, This patch is to fix: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61776 It records func decls whose const/pure flags are reset during instrumentation. After the loop resetting const/pure flags, find out stmts calling those recorded funcs and perform cfg fixup on them. bootstrap and regression test pass on x86_64-linux-gnu. ok for trunk and gcc-4_9? Thanks, Wei. ChangeLog: 2014-07-21 Wei Mi PR middle-end/61776 * tree-profile.c (tree_profiling): Fix cfg after the const/pure flags of some funcs are reset after instrumentation. 2014-07-21 Wei Mi PR middle-end/61776 * testsuite/gcc.dg/pr61776.c: New test. Index: tree-profile.c =================================================================== --- tree-profile.c (revision 212442) +++ tree-profile.c (working copy) @@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. #include "target.h" #include "tree-cfgcleanup.h" #include "tree-nested.h" +#include "pointer-set.h" static GTY(()) tree gcov_type_node; static GTY(()) tree tree_interval_profiler_fn; @@ -562,6 +563,9 @@ static unsigned int tree_profiling (void) { struct cgraph_node *node; + int i; + struct pointer_set_t *modified_constpure_decls; + vec modified_constpure_stmts; /* This is a small-ipa pass that gets called only once, from cgraphunit.c:ipa_passes(). */ @@ -603,6 +607,9 @@ tree_profiling (void) pop_cfun (); } + modified_constpure_decls = pointer_set_create (); + modified_constpure_stmts.create (0); + /* Drop pure/const flags from instrumented functions. */ FOR_EACH_DEFINED_FUNCTION (node) { @@ -615,6 +622,11 @@ tree_profiling (void) if (DECL_SOURCE_LOCATION (node->decl) == BUILTINS_LOCATION) continue; + /* If the const/pure flag of node is about to change, record + node->decl in modified_constpure_decls. */ + if (DECL_PURE_P (node->decl) || TREE_READONLY (node->decl)) + pointer_set_insert (modified_constpure_decls, node->decl); + cgraph_set_const_flag (node, false, false); cgraph_set_pure_flag (node, false, false); } @@ -623,6 +635,7 @@ tree_profiling (void) FOR_EACH_DEFINED_FUNCTION (node) { basic_block bb; + gimple stmt; if (!gimple_has_body_p (node->decl) || !(!node->clone_of @@ -642,10 +655,29 @@ tree_profiling (void) { gimple stmt = gsi_stmt (gsi); if (is_gimple_call (stmt)) - update_stmt (stmt); + { + tree decl = gimple_call_fndecl(stmt); + if (decl && pointer_set_contains (modified_constpure_decls, + decl)) + modified_constpure_stmts.safe_push (stmt); + update_stmt (stmt); + } } } + /* The const/pure flag of the decl of call stmt in modified_constpure_stmts + is changed because of instrumentation. Split block if the call stmt is not + the last stmt of bb and the call stmt ends bb. */ + FOR_EACH_VEC_ELT (modified_constpure_stmts, i, stmt) + { + basic_block bb = gimple_bb (stmt); + + if (stmt != gsi_stmt (gsi_last_bb (bb)) + && stmt_ends_bb_p (stmt)) + split_block (bb, stmt); + } + modified_constpure_stmts.release (); + /* re-merge split blocks. */ cleanup_tree_cfg (); update_ssa (TODO_update_ssa); @@ -657,6 +689,7 @@ tree_profiling (void) handle_missing_profiles (); + pointer_set_destroy (modified_constpure_decls); del_node_map (); return 0; } Index: testsuite/gcc.dg/pr61776.c =================================================================== --- testsuite/gcc.dg/pr61776.c (revision 0) +++ testsuite/gcc.dg/pr61776.c (revision 0) @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fprofile-generate" } */ + +#include + +int cond1, cond2; + +int goo() __attribute__((noinline)); + +int goo() { + if (cond1) + return 1; + else + return 2; +} + +jmp_buf env; +int foo() { + int a; + + setjmp(env); + if (cond2) + a = goo(); + else + a = 3; + return a; +}