From patchwork Tue Apr 10 14:40:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 896738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476143-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ispras.ru Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="WGWe+Bb7"; dkim-atps=neutral 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 40L8wh01sMz9s0n for ; Wed, 11 Apr 2018 00:40:35 +1000 (AEST) 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:mime-version:content-type; q=dns; s=default; b=i7vJoH6RZLMOPTexjqqoPVAFLQWQw9V6LqgfQe+NjOFOtPlVfc 8WteGt0yhllMkc/CW/jv+iCcbg8RlbFaTIJS9tzirf/2sXjnfJTLLlYkFnEDXNvz cz2mTVRV6pANOOXKHCH27DouZH0uLobsVfaranrB8kgBZOGycxwQYIw+I= 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:mime-version:content-type; s= default; bh=X9XjgLM/e9seSZSmuz9w/qfdTQw=; b=WGWe+Bb7tt+acdnj4mO2 zabg56RwWdApwCumwv+eqZP2nklXMjDGL/TrargHwWpM7fDe9zTpvjS8PgxRbrgd IJ3RWZNrenQf9w5ANfMXaQiNQyraSzV9xH5L1SowwshBPj9AjJzbODwrANO63nq0 bMjoB4ovUkpE6ypSF0lC7jY= Received: (qmail 24840 invoked by alias); 10 Apr 2018 14:40:29 -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 23783 invoked by uid 89); 10 Apr 2018 14:40:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=hosting, manner, 6919 X-HELO: smtp.ispras.ru Received: from bran.ispras.ru (HELO smtp.ispras.ru) (83.149.199.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Apr 2018 14:40:26 +0000 Received: from monopod.intra.ispras.ru (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id 3D4ED203B2; Tue, 10 Apr 2018 17:40:24 +0300 (MSK) Date: Tue, 10 Apr 2018 17:40:01 +0300 (MSK) From: Alexander Monakov To: gcc-patches@gcc.gnu.org cc: Andrey Belevantsev Subject: [PATCH] sel-sched: run cleanup_cfg just before loop_optimizer_init (PR 84659) Message-ID: User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 Hi, We have this code in sel-sched.c sel_region_init(): 6918 /* Init correct liveness sets on each instruction of a single-block loop. 6919 This is the only situation when we can't update liveness when calling 6920 compute_live for the first insn of the loop. */ 6921 if (current_loop_nest) 6922 { 6923 int header = 6924 (sel_is_loop_preheader_p (BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (0))) 6925 ? 1 6926 : 0); 6927 6928 if (current_nr_blocks == header + 1) 6929 update_liveness_on_insn 6930 (sel_bb_head (BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (header)))); 6931 } It appears it does not account for presence of empty BBs between the preheader and the "actual header" BB hosting the first insn of the loop. The testcase in the PR provides an example where we don't run update_liveness_on_insn here, but then remove the empty BB and recurse endlessly in compute_live_after_bb. This patch solves this in a brute-but-straightforward manner by invoking cleanup_cfg just before loop_optimizer_init. Bootstrapped/regtested on x86_64 together with the other two patches and also checked on a powerpc cross-compiler that the testcase is fixed. OK to apply? Thanks. Alexander PR rtl-optimization/85659 * sel-sched-ir.c (sel_init_pipelining): Invoke cleanup_cfg. * gcc.dg/pr84659.c: New test. diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c index ee970522890..aef380a7e80 100644 --- a/gcc/sel-sched-ir.c +++ b/gcc/sel-sched-ir.c @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "cfgrtl.h" #include "cfganal.h" #include "cfgbuild.h" +#include "cfgcleanup.h" #include "insn-config.h" #include "insn-attr.h" #include "recog.h" @@ -6121,6 +6122,7 @@ make_regions_from_loop_nest (struct loop *loop) void sel_init_pipelining (void) { + cleanup_cfg (0); /* Collect loop information to be used in outer loops pipelining. */ loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_FALLTHRU_PREHEADERS diff --git a/gcc/testsuite/gcc.dg/pr84659.c b/gcc/testsuite/gcc.dg/pr84659.c index e69de29bb2d..94c885f3869 100644 --- a/gcc/testsuite/gcc.dg/pr84659.c +++ b/gcc/testsuite/gcc.dg/pr84659.c @@ -0,0 +1,19 @@ +/* PR rtl-optimization/84659 */ +/* { dg-do compile { target powerpc*-*-* ia64-*-* i?86-*-* x86_64-*-* } } */ +/* { dg-options "-O2 -fselective-scheduling -fsel-sched-pipelining -fno-split-wide-types -fno-strict-aliasing -fno-tree-dce" } */ + +void +jk (int **lq, int *k4, long long int qv, int od) +{ + while (**lq < 1) + { + int uo; + + uo = ((od == 0) ? qv : *k4) != 1; + ++**lq; + } + + for (;;) + { + } +}