From patchwork Mon Oct 20 10:46:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 401060 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 BE4AF14007B for ; Mon, 20 Oct 2014 21:47:16 +1100 (AEDT) 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:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=AxhMDNhTWut53wCpG ws+mnpHvSlrzcXlqa1IFN+xJSniCGKjLbYrLS1E/T/4maJ9ETXlNda3LCynwtF5N MC7wIIpz0VwhttWSkWU3M1iclouPPhbD7ZDXa/8+FY6UKnhirHXnr4KE1jL6Knkz Ec0bMgU3GfdL4wPaNmrO+IGhD0= 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:references:mime-version :content-type:in-reply-to; s=default; bh=odJ6yVSL9mVBH44/kchOPcW Nkns=; b=ItVGvSF1TiCN6n5eKeXnLnia2Hb4azyGYQeniERuRxP8qNWluEeaUWY Jt04jsmtHpryBfmD/iQGgTeiHBIRp88EGxlSrInwrJHOjZGwqd4kun5/TuI+IotT lPbaNGoi/MKX8g9w8/Z0Kejd8amoruF/24azv8oDC4yjTvz2kGK4= Received: (qmail 24209 invoked by alias); 20 Oct 2014 10:47:10 -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 24193 invoked by uid 89); 20 Oct 2014 10:47:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f44.google.com Received: from mail-pa0-f44.google.com (HELO mail-pa0-f44.google.com) (209.85.220.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 20 Oct 2014 10:47:08 +0000 Received: by mail-pa0-f44.google.com with SMTP id et14so4991630pad.3 for ; Mon, 20 Oct 2014 03:47:06 -0700 (PDT) X-Received: by 10.70.55.40 with SMTP id o8mr26314169pdp.87.1413802026179; Mon, 20 Oct 2014 03:47:06 -0700 (PDT) Received: from bubble.grove.modra.org ([58.160.155.134]) by mx.google.com with ESMTPSA id ps7sm8795402pbb.73.2014.10.20.03.47.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Oct 2014 03:47:05 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 50384EA00F0; Mon, 20 Oct 2014 21:16:57 +1030 (ACDT) Date: Mon, 20 Oct 2014 21:16:57 +1030 From: Alan Modra To: Jakub Jelinek Cc: GCC Patches , Richard Biener Subject: Re: PR debug/60655, debug loc expressions Message-ID: <20141020104656.GU4267@bubble.grove.modra.org> Mail-Followup-To: Jakub Jelinek , GCC Patches , Richard Biener References: <20140904122150.GL17693@bubble.grove.modra.org> <20140905013004.GN17693@bubble.grove.modra.org> <20140909115027.GR17693@bubble.grove.modra.org> <20140909143050.GU17454@tucnak.redhat.com> <20140910021629.GS17693@bubble.grove.modra.org> <20141016065557.GJ4267@bubble.grove.modra.org> <20141016070758.GF10376@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20141016070758.GF10376@tucnak.redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On Thu, Oct 16, 2014 at 09:07:58AM +0200, Jakub Jelinek wrote: > So, please find the spot where we forget to simplify stuff, and put the > simplification there. You were correct to be suspicious that we weren't simplifying as we should. After more time in the debugger than I care to admit, I found the underlying cause. One of the var loc expressions is (plus:SI (plus:SI (not:SI (debug_expr:SI D#9)) (value/u:SI 58:4373 @0x18d3968/0x18ef230)) (debug_expr:SI D#5)) which after substitution (in bb7) becomes (plus:SI (plus:SI (not:SI (plus:SI (reg:SI 5 5 [orig:212 D.2333 ] [212]) (const:SI (plus:SI (symbol_ref:SI ("*.LANCHOR0") [flags 0x182]) (const_int -1 [0xffffffffffffffff]))))) (reg:SI 10 10 [orig:223 ivtmp.33 ] [223])) (plus:SI (reg:SI 5 5 [orig:212 D.2333 ] [212]) (const:SI (plus:SI (symbol_ref:SI ("*.LANCHOR0") [flags 0x182]) (const_int 323 [0x143]))))) The above has 8 ops by the time you turn ~x into -x - 1, and exceeds the allowed number of elements in the simplify_plus_minus ops array. Note that the ops array has 8 elements but the code only allows 7 to be entered, a bug since the "spare" element isn't a sentinal or used in any other way. This resulted in a partial simplification of the expression to (plus:SI (plus:SI (reg:SI 10 10 [orig:223 ivtmp.33 ] [223]) (symbol_ref:SI ("*.LANCHOR0") [flags 0x182])) (const:SI (minus:SI (const_int 323 [0x143]) (symbol_ref:SI ("*.LANCHOR0") [flags 0x182])))) I also noticed another small bug in simplify_plus_minus. n_constants ought to be the number of constants in ops, not the number of times we look at a constant. The "Handle CONST wrapped NOT, NEG and MINUS" in the previous patch seems to no longer be necessary, so I took that out (didn't hit the code in powerpc64-linux, powerpc-linux and x86_64-linux bootstrap and regression tests). Bootstrapped and regression tested powerpc64-linux and x86_64-linux. OK to apply? PR debug/60655 * simplify-rtx.c (simplify_plus_minus): Delete unused "input_ops". Increase "ops" array size. Correct array size tests. Init n_constants in loop. Break out of innermost loop when finding a trivial CONST expression. Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c (revision 216420) +++ gcc/simplify-rtx.c (working copy) @@ -3965,10 +3965,10 @@ simplify_plus_minus (enum rtx_code code, enum machine_mode mode, rtx op0, rtx op1) { - struct simplify_plus_minus_op_data ops[8]; + struct simplify_plus_minus_op_data ops[16]; rtx result, tem; - int n_ops = 2, input_ops = 2; - int changed, n_constants = 0, canonicalized = 0; + int n_ops = 2; + int changed, n_constants, canonicalized = 0; int i, j; memset (ops, 0, sizeof ops); @@ -3985,6 +3985,7 @@ do { changed = 0; + n_constants = 0; for (i = 0; i < n_ops; i++) { @@ -3996,7 +3997,7 @@ { case PLUS: case MINUS: - if (n_ops == 7) + if (n_ops == ARRAY_SIZE (ops)) return NULL_RTX; ops[n_ops].op = XEXP (this_op, 1); @@ -4004,7 +4005,6 @@ n_ops++; ops[i].op = XEXP (this_op, 0); - input_ops++; changed = 1; canonicalized |= this_neg; break; @@ -4017,7 +4017,7 @@ break; case CONST: - if (n_ops < 7 + if (n_ops != ARRAY_SIZE (ops) && GET_CODE (XEXP (this_op, 0)) == PLUS && CONSTANT_P (XEXP (XEXP (this_op, 0), 0)) && CONSTANT_P (XEXP (XEXP (this_op, 0), 1))) @@ -4033,7 +4033,7 @@ case NOT: /* ~a -> (-a - 1) */ - if (n_ops != 7) + if (n_ops != ARRAY_SIZE (ops)) { ops[n_ops].op = CONSTM1_RTX (mode); ops[n_ops++].neg = this_neg; @@ -4097,7 +4097,7 @@ /* Now simplify each pair of operands until nothing changes. */ do { - /* Insertion sort is good enough for an eight-element array. */ + /* Insertion sort is good enough for a small array. */ for (i = 1; i < n_ops; i++) { struct simplify_plus_minus_op_data save; @@ -4148,16 +4148,21 @@ else tem = simplify_binary_operation (ncode, mode, lhs, rhs); - /* Reject "simplifications" that just wrap the two - arguments in a CONST. Failure to do so can result - in infinite recursion with simplify_binary_operation - when it calls us to simplify CONST operations. */ - if (tem - && ! (GET_CODE (tem) == CONST - && GET_CODE (XEXP (tem, 0)) == ncode - && XEXP (XEXP (tem, 0), 0) == lhs - && XEXP (XEXP (tem, 0), 1) == rhs)) + if (tem) { + /* Reject "simplifications" that just wrap the two + arguments in a CONST. Failure to do so can result + in infinite recursion with simplify_binary_operation + when it calls us to simplify CONST operations. + Also, if we find such a simplification, don't try + any more combinations with this rhs: We must have + something like symbol+offset, ie. one of the + trivial CONST expressions we handle later. */ + if (GET_CODE (tem) == CONST + && GET_CODE (XEXP (tem, 0)) == ncode + && XEXP (XEXP (tem, 0), 0) == lhs + && XEXP (XEXP (tem, 0), 1) == rhs) + break; lneg &= rneg; if (GET_CODE (tem) == NEG) tem = XEXP (tem, 0), lneg = !lneg;