From patchwork Wed Dec 14 15:46:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 88039 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp262110qgi; Wed, 14 Dec 2016 07:46:31 -0800 (PST) X-Received: by 10.98.15.5 with SMTP id x5mr107169209pfi.140.1481730391414; Wed, 14 Dec 2016 07:46:31 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id k5si53393001pfk.138.2016.12.14.07.46.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Dec 2016 07:46:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444420-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444420-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444420-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=hVTBuetLNvdwisr5C rhntVLcK25XCn0ZJkPh52B9f8pyx+kLk7pwAoeRWdfVZ7mRDgEBbnraZ+tFj0y8t DnrSF/wVe/Efo/ryhASf4PBxM5tShRZwY4fdMhgXCYZIOtpGq4HRXWMYwGtlNX4W 5rRBxuVF5Tq1UqogXw0vrpMxcg= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=iAlWNc0TM9NWwbFROrtF/ig 0i6k=; b=D50IxagfUs9QPamWc7Wj4SJ3WUnw5cV4gxH1+l5bxezpUoffRbmhyPF 5xMXdc4Aoax1+GMp+Rj4Ksbyk48YVrVf4txmw5H5SlJH03SSEK1aBVSfwGVtWDwh WA9x/9P0+Yleh1+UlNXEEHt0dYke4VfEy3UI+rzk2DwdTGCIT9Yk= Received: (qmail 100133 invoked by alias); 14 Dec 2016 15:46:14 -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 100119 invoked by uid 89); 14 Dec 2016 15:46:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=dg-warning, dgwarning X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Dec 2016 15:46:12 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B84F3D94D; Wed, 14 Dec 2016 15:46:11 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-24.ams2.redhat.com [10.36.116.24]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBEFk9v5025840; Wed, 14 Dec 2016 10:46:10 -0500 Subject: Re: cprop fix for PR78626 To: Segher Boessenkool References: <20161210195856.GA30845@gate.crashing.org> <002615e4-1159-4eab-e7a8-70223f9ce5f5@redhat.com> Cc: GCC Patches From: Bernd Schmidt Message-ID: Date: Wed, 14 Dec 2016 16:46:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <002615e4-1159-4eab-e7a8-70223f9ce5f5@redhat.com> X-IsSubscribed: yes On 12/12/2016 03:21 PM, Bernd Schmidt wrote: > On 12/10/2016 08:58 PM, Segher Boessenkool wrote: >> On Thu, Dec 08, 2016 at 01:21:04PM +0100, Bernd Schmidt wrote: >>> This is another case where an optimization turns a trap_if >>> unconditional. We have to defer changing the CFG, since the rest of >>> cprop seems to blow up when we modify things while scanning. > >> The problem for PR78727 is that we also need to do this for insns that >> already are the last insn in the block: >> >>> + while (!uncond_traps.is_empty ()) >>> + { >>> + rtx_insn *insn = uncond_traps.pop (); >>> + basic_block to_split = BLOCK_FOR_INSN (insn); >>> + remove_edge (split_block (to_split, insn)); >>> + emit_barrier_after_bb (to_split); >>> + } >> >> We need that barrier, and we also need the successor edges removed >> (which split_block+remove_edge does). >> >> (PR78727 works fine with just that BB_END test deleted). > > Ah, ok. In that case I'll probably also add a test to make sure this is > only done for insns that weren't an unconditional trap before. Retesting... That would be this patch. Tested as before. The two new testcases seem to pass with a ppc cross (but I would appreciate if someone were to run full tests on ppc). Bernd PR rtl-optimization/78626 PR rtl-optimization/78727 * cprop.c (one_cprop_pass): Collect unconditional traps in the middle of a block, and split such blocks after everything else is finished. PR rtl-optimization/78626 PR rtl-optimization/78727 * gcc.dg/torture/pr78626.c: New test. * gcc.dg/torture/pr78727.c: New test. Index: gcc/cprop.c =================================================================== --- gcc/cprop.c (revision 243548) +++ gcc/cprop.c (working copy) @@ -1794,7 +1794,7 @@ one_cprop_pass (void) if (set_hash_table.n_elems > 0) { basic_block bb; - rtx_insn *insn; + auto_vec uncond_traps; alloc_cprop_mem (last_basic_block_for_fn (cfun), set_hash_table.n_elems); @@ -1810,6 +1810,9 @@ one_cprop_pass (void) EXIT_BLOCK_PTR_FOR_FN (cfun), next_bb) { + bool seen_uncond_trap = false; + rtx_insn *insn; + /* Reset tables used to keep track of what's still valid [since the start of the block]. */ reset_opr_set_tables (); @@ -1817,6 +1820,10 @@ one_cprop_pass (void) FOR_BB_INSNS (bb, insn) if (INSN_P (insn)) { + bool was_uncond_trap + = (GET_CODE (PATTERN (insn)) == TRAP_IF + && XEXP (PATTERN (insn), 0) == const1_rtx); + changed |= cprop_insn (insn); /* Keep track of everything modified by this insn. */ @@ -1825,11 +1832,27 @@ one_cprop_pass (void) insn into a NOTE, or deleted the insn. */ if (! NOTE_P (insn) && ! insn->deleted ()) mark_oprs_set (insn); + + if (!was_uncond_trap && !seen_uncond_trap + && GET_CODE (PATTERN (insn)) == TRAP_IF + && XEXP (PATTERN (insn), 0) == const1_rtx) + { + seen_uncond_trap = true; + uncond_traps.safe_push (insn); + } } } changed |= bypass_conditional_jumps (); + while (!uncond_traps.is_empty ()) + { + rtx_insn *insn = uncond_traps.pop (); + basic_block to_split = BLOCK_FOR_INSN (insn); + remove_edge (split_block (to_split, insn)); + emit_barrier_after_bb (to_split); + } + FREE_REG_SET (reg_set_bitmap); free_cprop_mem (); } Index: gcc/testsuite/gcc.dg/torture/pr78626.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr78626.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr78626.c (working copy) @@ -0,0 +1,27 @@ +/* { dg-do compile } */ + +int qs; + +void +ms (int g1) +{ + int cy; + int *fr = &cy; + + for (;;) + { + *fr = 1; + fr = &g1; + + while (qs != 0) + { + if (qs | cy) + qs = g1 / 0; /* { dg-warning "division" } */ + ++qs; + } + + cy = 1; + while (cy != 0) + cy = 2; + } +} Index: gcc/testsuite/gcc.dg/torture/pr78727.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr78727.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr78727.c (working copy) @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +int +dd (int gj, unsigned int o7) +{ + long long int e8 = gj; + + e8 |= gj + 1u; + if (e8 != 0) + { + short int *mn = (short int *)&e8; + int pv; + + e8 &= e8 > gj; + gj = o7 > e8; + pv = ((gj != 0) ? gj : *mn) && e8; + gj |= *mn / pv; + } + + return gj; +}