From patchwork Wed May 15 16:20:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 244129 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id C6B152C007E for ; Thu, 16 May 2013 02:20:24 +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=vDk4obtrCdgQyXVDr7HnrNS/Zak6Go257Qt94Vxzy5s Z0XIfzzNxkSfk6ibvO6HNTVrRCcBZp0YgY3cAdCepYCBMKPu2vqS53xq/tPNIm8j iaJuVQvw51c7HDib947Ujvw9Inw2jLtUFbRED/WWDeCyYlg8kaR+bLsth1fnIExE = 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=MN3wuBwCIf62lkZmluajl6IumsE=; b=IdKahi2Np+WirfP8r BpSxASUjGq35yPrtFj9flYjnwP+q9/anz6MTCwZ3Heq1n2m+PiRnw8CM0uTlBI12 j/xFTfgD0dHF4AzhXckSc0ZN9xWM2sAtFiazBsm/TUBghK6ZH79fjEZLD+absc5M QoWtIKfyi+sN/voUTPBDG6dI/A= Received: (qmail 22928 invoked by alias); 15 May 2013 16:20:18 -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 22919 invoked by uid 89); 15 May 2013 16:20:18 -0000 X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, TW_GD, TW_TM autolearn=ham version=3.3.1 Received: from mail-ea0-f169.google.com (HELO mail-ea0-f169.google.com) (209.85.215.169) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 15 May 2013 16:20:17 +0000 Received: by mail-ea0-f169.google.com with SMTP id m14so1199791eaj.28 for ; Wed, 15 May 2013 09:20:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to:cc :content-type:x-gm-message-state; bh=qmCmou7NLMIixH5Mb7hiVgNsr9oeOpBP7PFe0S4g1No=; b=d+h+eYYL10o5aAUhnbsR3ph+I9/xJgTI89CzUiCXLXYy+juHFFif288Cs1aE7c76Vq iS9s8UVrV+ZBKbYSnBPZWrGi1GPGkHT0woZlFgywoMaFHHmV2U7kF+vX8vg0bgVoOI2A zGTgUDg3HPbPFPj4OLrk9WkPw9Bxa82kI3ABFBx9+aslXHskpT19BDQ0oIrkdlSSa7cU dXcIZZbUGc0YWE7GfDnJ0+ajhdsyTffe2pzTf4EV3m8HLEajoFQhRiFAoMiz1avzr6QC MFozzc9FDrAPdpoziD/OAeLw4pp/NGHKymX380OHiU6VlLAavPxiS9UQ9uKnzLCwivk1 IAEA== MIME-Version: 1.0 X-Received: by 10.14.69.138 with SMTP id n10mr104821303eed.32.1368634815055; Wed, 15 May 2013 09:20:15 -0700 (PDT) Received: by 10.14.175.131 with HTTP; Wed, 15 May 2013 09:20:14 -0700 (PDT) Date: Wed, 15 May 2013 09:20:14 -0700 Message-ID: Subject: [PATCH] Fix incorrect discriminator assignment. From: Dehao Chen To: GCC Patches Cc: Cary Coutant X-Gm-Message-State: ALoCoQmd0QkFW3RTa3ZwvCDapSTrXrq7vULzzov5J3ruVHHCBonsG85LyIMDtAR7rWJD2hR7/xwJ5O7bHcOt0IgsYs5CZONPP0aNs3UiK4Ufsc4ff340XxOAOG4iFi71friZfUAGLyeSc87rZe6wfsSsgfod52xbxGuWwh/roqiARmtFmGJtIsFW9AChx3hjFilNfJHKGuhv X-Virus-Found: No This patch fixes a common case where one line is distributed to 3 BBs, but only 1 discriminator is assigned. Bootstrapped and passed gcc regression test. OK for trunk? Thanks, Dehao gcc/ChangeLog: * tree-cfg.c (locus_descrim_hasher::hash): Only hash lineno. (locus_descrim_hasher::equal): Likewise. (next_discriminator_for_locus): Likewise. (assign_discriminator): Add return value. (make_edges): Assign more discriminator if necessary. (make_cond_expr_edges): Likewise. (make_goto_expr_edges): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/debug/dwarf2/discriminator.c: New Test. Index: gcc/testsuite/gcc.dg/debug/dwarf2/discriminator.c =================================================================== --- gcc/testsuite/gcc.dg/debug/dwarf2/discriminator.c (revision 0) +++ gcc/testsuite/gcc.dg/debug/dwarf2/discriminator.c (revision 0) @@ -0,0 +1,16 @@ +/* { dg-do compile { target { i?86-*-* x86_64-*-* } } } */ +/* { dg-options "-O0 -gdwarf-2" } */ +/* { dg-final { scan-assembler "loc \[0-9] 9 \[0-9]( is_stmt \[0-9])?\n" } } */ +/* { dg-final { scan-assembler "loc \[0-9] 9 \[0-9]( is_stmt \[0-9])? discriminator 2\n" } } */ +/* { dg-final { scan-assembler "loc \[0-9] 9 \[0-9]( is_stmt \[0-9])? discriminator 1\n" } } */ + +int foo(int n) { + int i, ret = 0; + for (i = 0; i < n; i++) { + if (i % 10 == 1) + ret++; + else + ret--; + } + return ret; +} Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c (revision 198891) +++ gcc/tree-cfg.c (working copy) @@ -105,7 +105,7 @@ struct locus_descrim_hasher : typed_free_remove locus; + return LOCATION_LINE (item->locus); } /* Equality function for the locus-to-discriminator map. A and B @@ -114,7 +114,7 @@ locus_descrim_hasher::hash (const value_type *item inline bool locus_descrim_hasher::equal (const value_type *a, const compare_type *b) { - return a->locus == b->locus; + return LOCATION_LINE (a->locus) == LOCATION_LINE (b->locus); } static hash_table discriminator_per_locus; @@ -129,7 +129,7 @@ static void make_cond_expr_edges (basic_block); static void make_gimple_switch_edges (basic_block); static void make_goto_expr_edges (basic_block); static void make_gimple_asm_edges (basic_block); -static void assign_discriminator (location_t, basic_block); +static bool assign_discriminator (location_t, basic_block); static edge gimple_redirect_edge_and_branch (edge, basic_block); static edge gimple_try_redirect_by_replacing_jump (edge, basic_block); static unsigned int split_critical_edges (void); @@ -693,7 +693,8 @@ make_edges (void) { make_edge (bb, bb->next_bb, EDGE_FALLTHRU); if (last) - assign_discriminator (gimple_location (last), bb->next_bb); + if (assign_discriminator (gimple_location (last), bb->next_bb)) + assign_discriminator (gimple_location (last), bb); } } @@ -717,7 +718,8 @@ next_discriminator_for_locus (location_t locus) item.locus = locus; item.discriminator = 0; - slot = discriminator_per_locus.find_slot_with_hash (&item, locus, INSERT); + slot = discriminator_per_locus.find_slot_with_hash ( + &item, LOCATION_LINE (locus), INSERT); gcc_assert (slot); if (*slot == HTAB_EMPTY_ENTRY) { @@ -753,21 +755,29 @@ same_line_p (location_t locus1, location_t locus2) } /* Assign a unique discriminator value to block BB if it begins at the same - LOCUS as its predecessor block. */ + LOCUS as its pred/succ block. Return true if discriminator has already + been assigned for BB and needs to assign additional discriminator for + BB's predecessor. */ -static void +static bool assign_discriminator (location_t locus, basic_block bb) { gimple first_in_to_bb, last_in_to_bb; - if (locus == 0 || bb->discriminator != 0) - return; + if (locus == 0) + return false; first_in_to_bb = first_non_label_stmt (bb); last_in_to_bb = last_stmt (bb); if ((first_in_to_bb && same_line_p (locus, gimple_location (first_in_to_bb))) || (last_in_to_bb && same_line_p (locus, gimple_location (last_in_to_bb)))) - bb->discriminator = next_discriminator_for_locus (locus); + { + if (bb->discriminator != 0) + return true; + else + bb->discriminator = next_discriminator_for_locus (locus); + } + return false; } /* Create the edges for a GIMPLE_COND starting at block BB. */ @@ -796,12 +806,14 @@ make_cond_expr_edges (basic_block bb) else_stmt = first_stmt (else_bb); e = make_edge (bb, then_bb, EDGE_TRUE_VALUE); - assign_discriminator (entry_locus, then_bb); + if (assign_discriminator (entry_locus, then_bb)) + assign_discriminator (entry_locus, bb); e->goto_locus = gimple_location (then_stmt); e = make_edge (bb, else_bb, EDGE_FALSE_VALUE); if (e) { - assign_discriminator (entry_locus, else_bb); + if (assign_discriminator (entry_locus, else_bb)) + assign_discriminator (entry_locus, bb); e->goto_locus = gimple_location (else_stmt); } @@ -1020,7 +1032,8 @@ make_goto_expr_edges (basic_block bb) basic_block label_bb = label_to_block (dest); edge e = make_edge (bb, label_bb, EDGE_FALLTHRU); e->goto_locus = gimple_location (goto_t); - assign_discriminator (e->goto_locus, label_bb); + if (assign_discriminator (e->goto_locus, label_bb)) + assign_discriminator (e->goto_locus, bb); gsi_remove (&last, true); return; }