From patchwork Thu Dec 12 14:29:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Zhuykov X-Patchwork-Id: 1208536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515798-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (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="vHbvxwA1"; 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 47YbmK2rvLz9sPn for ; Fri, 13 Dec 2019 01:29:50 +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 :mime-version:content-type:date:from:to:subject:message-id; q= dns; s=default; b=L6zN4H1l4acL8b+3ihzIWxgHOomwgHP0CLANJXVTy5bZRU dPxFeA6OId/qC2m0aoTEdu9CBqrOUGl3o7FXioBEw8+jEk52D0Hrd37uDzIKMns6 WDrtNSgW++b7fmd3bv6WDHA4rMoYejhiDnwUgP/D/9DEEs77i6jhqNSFhIdl8= 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 :mime-version:content-type:date:from:to:subject:message-id; s= default; bh=m9WGYPe5AOxfXEMRU913Kza7dGI=; b=vHbvxwA1t6NCavNr6345 LYz2QwbQltGWbiwgE5SWVxjSfhvUHug539TZ3YPT55Z/lKXDD9Eqp+gbTr6luKLE XUA1L4pb20rQQ0rsUxAoONoPbgRmk3/MQXpy/pmcot0FzK2X0O0mK9wmndMBxIgB KvYDEkRVxxnJRI3MFb5/E2g= Received: (qmail 115702 invoked by alias); 12 Dec 2019 14:29:42 -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 115693 invoked by uid 89); 12 Dec 2019 14:29:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=tuning, sk:dg-addi, H*r:MSK, threshold X-HELO: mail.ispras.ru Received: from mail.ispras.ru (HELO mail.ispras.ru) (83.149.199.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Dec 2019 14:29:39 +0000 Received: from mail.ispras.ru (localhost [127.0.0.1]) by mail.ispras.ru (Postfix) with ESMTPSA id 166DE540022 for ; Thu, 12 Dec 2019 17:29:36 +0300 (MSK) MIME-Version: 1.0 Date: Thu, 12 Dec 2019 17:29:36 +0300 From: Roman Zhuykov To: gcc-patches@gcc.gnu.org Subject: [modulo-sched][PATCH] Fix PR92591 Message-ID: <31e99da8-0b2b-d19d-aeb2-253e7f57ca80@ispras.ru> X-Sender: zhroma@ispras.ru User-Agent: Roundcube Webmail/1.1.2 X-IsSubscribed: yes Hello. As pointed out in the PR https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92591#c1, the test can be fixed by DFA-checking more adjacent row sequences in the partial schedule. I've found that on powerpc64 gcc.c-torture/execute/pr61682.c test catches same issue with -Os -fmodulo-sched-allow-regmoves with some non-zero sms-dfa-history parameter values, so I added that test using #include as second test into the patch. Minor separate patch about modulo-sched parameters is also attached. If no objection, I'll commit this two patches into trunk tomorrow together with my PR90001 fix. Trunk and 8/9 branches succesfully regstrapped on x64, and cross-compiler check-gcc tested on ppc, ppc64, arm, aarch64, ia64 and s390. Certainly a lot of testing were also done with changing default sms-dfa-history value to some other than zero. Roman gcc/ChangeLog: 2019-12-10 Roman Zhuykov * modulo-sched.c (ps_add_node_check_conflicts): Improve checking for history > 0 case. gcc/testsuite/ChangeLog: 2019-12-10 Roman Zhuykov * gcc.dg/pr92951-1.c: New test. * gcc.dg/pr92951-2.c: New test. gcc/ChangeLog: 2019-11-26 Roman Zhuykov * modulo-sched.c (sms_schedule): Use param_sms_max_ii_factor value instead of macro. Adjust comment. (sms_schedule_by_order): Use parameter value without macro. * params.opt: Add ranges for modulo scheduler parameters, set param_sms_max_ii_factor = 2 by default. diff --git a/gcc/modulo-sched.c b/gcc/modulo-sched.c index 98af549..2dc9af7 100644 --- a/gcc/modulo-sched.c +++ b/gcc/modulo-sched.c @@ -1331,9 +1331,6 @@ setup_sched_infos (void) version may be entered. Just a guess. */ #define PROB_SMS_ENOUGH_ITERATIONS 80 -/* Used to calculate the upper bound of ii. */ -#define MAXII_FACTOR 2 - /* Main entry point, perform SMS scheduling on the loops of the function that consist of single basic blocks. */ static void @@ -1597,7 +1594,7 @@ sms_schedule (void) rec_mii = sms_order_nodes (g, mii, node_order, &max_asap); mii = MAX (res_MII (g), rec_mii); mii = MAX (mii, 1); - maxii = MAX (max_asap, MAXII_FACTOR * mii); + maxii = MAX (max_asap, param_sms_max_ii_factor * mii); if (dump_file) fprintf (dump_file, "SMS iis %d %d %d (rec_mii, mii, maxii)\n", @@ -1636,7 +1633,7 @@ sms_schedule (void) gcc_assert (stage_count >= 1); } - /* The default value of PARAM_SMS_MIN_SC is 2 as stage count of + /* The default value of param_sms_min_sc is 2 as stage count of 1 means that there is no interleaving between iterations thus we let the scheduling passes do the job in this case. */ if (stage_count < param_sms_min_sc @@ -1828,11 +1825,6 @@ sms_schedule (void) The window would then start and end on the same row, but with different "must precede" and "must follow" requirements. */ -/* A limit on the number of cycles that resource conflicts can span. ??? Should - be provided by DFA, and be dependent on the type of insn scheduled. Currently - set to 0 to save compile time. */ -#define DFA_HISTORY param_sms_dfa_history - /* A threshold for the number of repeated unsuccessful attempts to insert an empty row, before we flush the partial schedule and start over. */ #define MAX_SPLIT_NUM 10 @@ -2136,7 +2128,12 @@ sms_schedule_by_order (ddg_ptr g, int mii, int maxii, int *nodes_order) auto_sbitmap must_follow (num_nodes); auto_sbitmap tobe_scheduled (num_nodes); - partial_schedule_ptr ps = create_partial_schedule (ii, g, DFA_HISTORY); + /* Value of param_sms_dfa_history is a limit on the number of cycles that + resource conflicts can span. ??? Should be provided by DFA, and be + dependent on the type of insn scheduled. Set to 0 by default to save + compile time. */ + partial_schedule_ptr ps = create_partial_schedule (ii, g, + param_sms_dfa_history); bitmap_ones (tobe_scheduled); bitmap_clear (sched_nodes); diff --git a/gcc/params.opt b/gcc/params.opt index 586b539..d960f4a 100644 --- a/gcc/params.opt +++ b/gcc/params.opt @@ -809,7 +809,7 @@ Common Joined UInteger Var(param_slp_max_insns_in_bb) Init(1000) Param Maximum number of instructions in basic block to be considered for SLP vectorization. -param=sms-dfa-history= -Common Joined UInteger Var(param_sms_dfa_history) Param +Common Joined UInteger Var(param_sms_dfa_history) IntegerRange(0, 16) Param The number of cycles the swing modulo scheduler considers when checking conflicts using DFA. -param=sms-loop-average-count-threshold= @@ -817,11 +817,11 @@ Common Joined UInteger Var(param_sms_loop_average_count_threshold) Param A threshold on the average loop count considered by the swing modulo scheduler. -param=sms-max-ii-factor= -Common Joined UInteger Var(param_sms_max_ii_factor) Init(100) Param +Common Joined UInteger Var(param_sms_max_ii_factor) Init(2) IntegerRange(1, 16) Param A factor for tuning the upper bound that swing modulo scheduler uses for scheduling a loop. -param=sms-min-sc= -Common Joined UInteger Var(param_sms_min_sc) Init(2) IntegerRange(1, 65536) Param +Common Joined UInteger Var(param_sms_min_sc) Init(2) IntegerRange(1, 2) Param The minimum value of stage count that swing modulo scheduler will generate. -param=sra-max-scalarization-size-Osize= diff --git a/gcc/modulo-sched.c b/gcc/modulo-sched.c --- a/gcc/modulo-sched.c +++ b/gcc/modulo-sched.c @@ -3200,7 +3200,7 @@ ps_add_node_check_conflicts (partial_schedule_ptr ps, int n, int c, sbitmap must_precede, sbitmap must_follow) { - int has_conflicts = 0; + int i, first, amount, has_conflicts = 0; ps_insn_ptr ps_i; /* First add the node to the PS, if this succeeds check for @@ -3208,23 +3208,32 @@ ps_add_node_check_conflicts (partial_schedule_ptr ps, int n, if (! (ps_i = add_node_to_ps (ps, n, c, must_precede, must_follow))) return NULL; /* Failed to insert the node at the given cycle. */ - has_conflicts = ps_has_conflicts (ps, c, c) - || (ps->history > 0 - && ps_has_conflicts (ps, - c - ps->history, - c + ps->history)); - - /* Try different issue slots to find one that the given node can be - scheduled in without conflicts. */ - while (has_conflicts) + while (1) { + has_conflicts = ps_has_conflicts (ps, c, c); + if (ps->history > 0 && !has_conflicts) + { + /* Check all 2h+1 intervals, starting from c-2h..c up to c..2h, + but not more than ii intervals. */ + first = c - ps->history; + amount = 2 * ps->history + 1; + if (amount > ps->ii) + amount = ps->ii; + for (i = first; i < first + amount; i++) + { + has_conflicts = ps_has_conflicts (ps, + i - ps->history, + i + ps->history); + if (has_conflicts) + break; + } + } + if (!has_conflicts) + break; + /* Try different issue slots to find one that the given node can be + scheduled in without conflicts. */ if (! ps_insn_advance_column (ps, ps_i, must_follow)) break; - has_conflicts = ps_has_conflicts (ps, c, c) - || (ps->history > 0 - && ps_has_conflicts (ps, - c - ps->history, - c + ps->history)); } if (has_conflicts) diff --git a/gcc/testsuite/gcc.dg/pr92951-1.c b/gcc/testsuite/gcc.dg/pr92951-1.c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr92951-1.c @@ -0,0 +1,11 @@ +/* PR rtl-optimization/92591 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fmodulo-sched -fweb -fno-dce -fno-ivopts -fno-sched-pressure -fno-tree-loop-distribute-patterns --param sms-dfa-history=1" } */ +/* { dg-additional-options "-mcpu=e500mc" { target { powerpc-*-* } } } */ + +void +wf (char *mr, int tc) +{ + while (tc-- > 0) + *mr++ = 0; +} diff --git a/gcc/testsuite/gcc.dg/pr92951-2.c b/gcc/testsuite/gcc.dg/pr92951-2.c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr92951-2.c @@ -0,0 +1,5 @@ +/* PR rtl-optimization/92591 */ +/* { dg-do compile } */ +/* { dg-options "-Os -fmodulo-sched -fmodulo-sched-allow-regmoves --param sms-dfa-history=8" } */ + +#include "../gcc.c-torture/execute/pr61682.c"