From patchwork Tue Oct 30 23:55:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 195665 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]) by ozlabs.org (Postfix) with SMTP id A644E2C0095 for ; Wed, 31 Oct 2012 10:55:32 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352246133; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=l8+byy+B+fhH2BnPz7RbDJiWr1I=; b=xNF1Xw5CvLuoSMR8vFhcPqeDjMuBlsW9oqjFxTmAvxaGi3GvwFqiZNEEtp0VpI im2eGY5PHO7sVZ7kE+Lhvl55q7gB737at2iXZLqKLMArJfgPMxs8qvZUPq6VmFiV UNxrofOCq6nJ7FQ3GENspSAau/Ji2/ywgBw1QIMALryM0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Cc:Content-Type:X-System-Of-Record:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=BJVGkgAOnHbtlBS7/EGbXqECtIp9yJKqmYpz1Uf7Tg4r/qY11i0B+k0MgzaodH k+vIk01pVdV073bz+5FkgwTxyrOKrl/V1VbDouLAJw2JsNiGheaOVj7wrKVvPsUG FwNKhvyiEKtozmp5fC2cNcGFyrPdonL05OBmN9oUuUqrA=; Received: (qmail 12338 invoked by alias); 30 Oct 2012 23:55:28 -0000 Received: (qmail 12314 invoked by uid 22791); 30 Oct 2012 23:55:27 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_TM X-Spam-Check-By: sourceware.org Received: from mail-pb0-f47.google.com (HELO mail-pb0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 30 Oct 2012 23:55:22 +0000 Received: by mail-pb0-f47.google.com with SMTP id ro12so532304pbb.20 for ; Tue, 30 Oct 2012 16:55:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-system-of-record:x-gm-message-state; bh=Y6At6rqljtKiKIt2jRbGmXLLxH7I98rFpJSsTgsiZ5g=; b=dgxYMhVPkPiM4OW/JedH3dVfHccuerKolaCqX3gqY3Otowc2ekES0eT5oCu9ZPKcUN t38wVYijeYyVQqaLCfGqCg6xs7p2eFHSENW2Q8TqDGMFoggsaUltgbongHf5gcwdj6lc V6wA9LPnLT8M+90shQDXgMsPUvQrY9SVQLq3EaAbVJFeOzFomL4PK7VwIe/XdL8koaRy hWWBZ9Zt/tUxkoioVlpB72Gg/WhoRGW5GGO2RbJLnNZAOq9FNa2zF0nNCQVoinxVuf4l aXsZhACx9LFmPK3RkJz2t+4MwYmaiDBZYK9g1xN0SA0HRrMZN9EyHl9dz8AvHtpnapUi dmHw== MIME-Version: 1.0 Received: by 10.68.224.69 with SMTP id ra5mr106867886pbc.114.1351641321415; Tue, 30 Oct 2012 16:55:21 -0700 (PDT) Received: by 10.68.49.232 with HTTP; Tue, 30 Oct 2012 16:55:21 -0700 (PDT) In-Reply-To: References: Date: Tue, 30 Oct 2012 16:55:21 -0700 Message-ID: Subject: Re: [PATCH] Update source location for PRE inserted stmt From: Dehao Chen To: Steven Bosscher Cc: GCC Patches X-System-Of-Record: true X-Gm-Message-State: ALoCoQmJiHcRNAnY1/oMM73bPfAzzFdlptEcVtI78BZsFvoEb7km+GNAD52cxdg+vtjGTGgur/IL7HF1cL4mxETm3OobUrrYj7QF3qKP01VMeHDKa/TQ9mKUGS0RmvocE5YsH2vClomumVkFrIr++W7ApYKjJkQcgc3ZT/niy/YhXBUEC+Qs23hs1hdUg82BBuuKq5XmJ35M X-IsSubscribed: yes 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 Sorry, new patch attached... On Tue, Oct 30, 2012 at 4:38 PM, Steven Bosscher wrote: > On Wed, Oct 31, 2012 at 12:00 AM, Dehao Chen wrote: >> This patch aims to improve debugging of optimized code. It ensures >> that PRE inserted statements have the same source location as the >> statement at the insertion point, instead of UNKNOWN_LOCATION. > > Wrong patch attached. > > However, is it really better to have the location of the insertion > point than to have UNKNOWN_LOCATION? It's not where the value is > computed in the source program... Setting it to UNKNOWN_LOCATION is expecting it to inherit source location from its previous stmt. However, backend optimization could optimize the previous stmt away, making the inserted stmt with random location. This patch just enforce the location to be the same as previous stmt while insertion, so that random stuff does not happen. In general, we want to reduce the number of UNKNOWN_LOCATIONS emitted. At least we do not want to see UNKNOWN_LOCATION at the beginning of any BB. Thanks, Dehao > > Ciao! > Steven Index: gcc/tree-ssa-pre.c =================================================================== --- gcc/tree-ssa-pre.c (revision 192809) +++ gcc/tree-ssa-pre.c (working copy) @@ -3039,6 +3039,20 @@ inhibit_phi_insertion (basic_block bb, pre_expr ex return false; } +static void +insert_into_pred_update_location (edge pred, gimple_seq stmts) +{ + gimple_stmt_iterator gsi; + gimple stmt = last_stmt (pred->src); + location_t location = stmt ? gimple_location (stmt) + : UNKNOWN_LOCATION; + if (location != UNKNOWN_LOCATION) + for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi)) + if (gimple_location (gsi_stmt (gsi)) == UNKNOWN_LOCATION) + gimple_set_location (gsi_stmt (gsi), location); + gsi_insert_seq_on_edge (pred, stmts); +} + /* Insert the to-be-made-available values of expression EXPRNUM for each predecessor, stored in AVAIL, into the predecessors of BLOCK, and merge the result with a phi node, given the same value number as @@ -3094,7 +3108,7 @@ insert_into_preds_of_block (basic_block block, uns builtexpr = create_expression_by_pieces (bprime, eprime, &stmts, type); gcc_assert (!(pred->flags & EDGE_ABNORMAL)); - gsi_insert_seq_on_edge (pred, stmts); + insert_into_pred_update_location (pred, stmts); VEC_replace (pre_expr, avail, pred->dest_idx, get_or_alloc_expr_for_name (builtexpr)); insertions = true; @@ -3132,7 +3146,7 @@ insert_into_preds_of_block (basic_block block, uns SSA_NAME_VERSION (lhs)); gimple_set_plf (stmt, NECESSARY, false); } - gsi_insert_seq_on_edge (pred, stmts); + insert_into_pred_update_location (pred, stmts); } VEC_replace (pre_expr, avail, pred->dest_idx, get_or_alloc_expr_for_name (forcedexpr)); @@ -3177,7 +3191,7 @@ insert_into_preds_of_block (basic_block block, uns bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (lhs)); gimple_set_plf (stmt, NECESSARY, false); } - gsi_insert_seq_on_edge (pred, stmts); + insert_into_pred_update_location (pred, stmts); } VEC_replace (pre_expr, avail, pred->dest_idx, get_or_alloc_expr_for_name (forcedexpr)); Index: gcc/testsuite/gcc.dg/debug/dwarf2/pre.c =================================================================== --- gcc/testsuite/gcc.dg/debug/dwarf2/pre.c (revision 0) +++ gcc/testsuite/gcc.dg/debug/dwarf2/pre.c (revision 0) @@ -0,0 +1,18 @@ +// This test makes sure PRE will not optimize the debug info away. +// { dg-do compile { target { i?86-*-* x86_64-*-* } } } +// { dg-options "-O2 -g -dA" } +extern int x; + +int abc (int *a) +{ + int ret = 0; + + if (x > 0) + ret += *a; + else + a++; + + ret += *a; + return ret; +} +// { dg-final { scan-assembler "pre.c:13" } }