From patchwork Thu Dec 8 12:21:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 87238 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp814301qgi; Thu, 8 Dec 2016 04:21:25 -0800 (PST) X-Received: by 10.84.162.204 with SMTP id o12mr159772202plg.17.1481199685311; Thu, 08 Dec 2016 04:21:25 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a36si28613262pli.2.2016.12.08.04.21.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Dec 2016 04:21:25 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-443776-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-443776-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-443776-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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=SFCD4j7sZhkHeX2WTjTYeqfrCzolMNqNRPLmC7YWujb0oGkQIM 5fHIkgmtNs7klZ1m3iRgDnMGYHEZ+b9TlPWTbztP63NEgfe5l2AZJsb3szLjiQw1 EppK72u/oN1tO8P/9/rZVRSw/e6cSqQ37apMaHNfPfCplZ83OyuXT+TI4= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=N8KsaOodkMs/BBFxV6UXh3Y1Z8U=; b=HyQ9cGFGxYoVX85KTQYk V94Y92FdnnqDy/7cPK6ZZEwqFO8bY7MUgqcscjxgkGSu+KNHsCJFiDKLe2SaKeTi 1VIQgEQ76AQrbD8gowm/NO64cpS2aWmg1NtJ95SV8MBejWWvcv6tDISPOo6osgoE okTUFzEja4tirOeljZn9Jlo= Received: (qmail 98499 invoked by alias); 8 Dec 2016 12:21: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 98484 invoked by uid 89); 8 Dec 2016 12:21:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=cfg, H*Ad:U*bschmidt 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; Thu, 08 Dec 2016 12:21:06 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 65DC6C04B93A for ; Thu, 8 Dec 2016 12:21:05 +0000 (UTC) Received: from localhost.localdomain ([10.36.126.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB8CL4eV027203 for ; Thu, 8 Dec 2016 07:21:05 -0500 To: GCC Patches From: Bernd Schmidt Subject: cprop fix for PR78626 Message-ID: Date: Thu, 8 Dec 2016 13:21:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-IsSubscribed: yes 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. Bootstrapped and tested on x86_64-linux, and reportedly fixes the problem on ppc, ok? Bernd PR rtl-optimization/78626 * 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 * gcc.dg/torture/pr78626.c: New test. Index: gcc/cprop.c =================================================================== --- gcc/cprop.c (revision 243310) +++ 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) { + rtx_insn *first_uncond_trap = NULL; + rtx_insn *insn; + /* Reset tables used to keep track of what's still valid [since the start of the block]. */ reset_opr_set_tables (); @@ -1825,11 +1828,26 @@ one_cprop_pass (void) insn into a NOTE, or deleted the insn. */ if (! NOTE_P (insn) && ! insn->deleted ()) mark_oprs_set (insn); + + if (first_uncond_trap == NULL + && GET_CODE (PATTERN (insn)) == TRAP_IF + && XEXP (PATTERN (insn), 0) == const1_rtx) + first_uncond_trap = insn; } + if (first_uncond_trap != NULL && first_uncond_trap != BB_END (bb)) + uncond_traps.safe_push (first_uncond_trap); } 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; + } +}