From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id B68803858418 for ; Thu, 9 Nov 2023 09:10:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B68803858418 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B68803858418 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699521024; cv=none; b=nibcTAN7gSzE/xkHw80K7X6dAFoR1ysOas+nO/5MCTk6dTSfiFAOU06R8nBiQ42s5kbwsYz2Q5zV1DM7y3zQb6Vrk0OsNqgaeat0/emArOddNt7d8Ii0OXKXlaGpEiVyd2Ub6ky1mxv1lNQFOhck0KxHM8tyP3BUSVxvc4ZE724= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699521024; c=relaxed/simple; bh=8F26DQR8OVzUuRwyfNTc7B6kkxE5DdPk3wUaSxoz3yY=; h=DKIM-Signature:Mime-Version:Subject:From:Date:Message-Id:To; b=HntR28gZ77faZbEd3kamYeljr9PRMmrvj0oMyD7fuFqgoRZ2VnBZE8vFBYNhqJUm/11I6OdpgoWsXMS7sRzYc19N9wXIml3g14FZft9iAtI4TF31PzIl7WhJz2dkfhtJBqJsJL9obrQJC+SV5pLpEpoM9uZ1tmbtVgdzQGGO3oM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9c6f0530929so20915066b.1 for ; Thu, 09 Nov 2023 01:10:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699521019; x=1700125819; darn=gcc.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rrwPCfgnYncaTRDN4ebsSU76x5SayBBxwN0/erePvgo=; b=nhn+bwwucTeAl4qPLI82rtFdEdSL2wL84P1yScAEe3od2y3naYyNwBZ4HmP5ILe7Z8 5YyHr7gOGKbpfx/qU4R6CqYKOcux6GhTSv9wTgz1I2bOcp1fyPTDbcaxEFwRsDvmY//1 xEE/B/2PtQvtwfItKQrHKOBnyezysRxsDnNBufk8MZBkIDb2CfRV1iua4GuDkNyukF+h xtTG+Zg8lX3fxsO3ck8tYChWlvZV7EMI2V37EUw1e8OXMvieyAl4GpZstNajuO5L689L zDERq5MZlalh93aJ2lSfureKIE7CEBdwrlMfB7dCvhOirzMJriJDkteH11V3QL2oCxNV /T7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699521019; x=1700125819; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rrwPCfgnYncaTRDN4ebsSU76x5SayBBxwN0/erePvgo=; b=BNMF62fnp6VqSr1vi3ea8wORWOBs0PP/gJiMhHBbNRYh4aq4EwshShf/glaSQPJoGG 8EprQOSH86Y5HjgUCmli8V6DSkE3Q46gJhzNAuWBMTxDBnOB2wQ1yCaRH9lUOibzOwYi wqwJ5FpkPQHVtIvL2mgoJ++tQRBNJmyQZi8CdUM72R3ADeCM3uAvDd2gaYJyUuijWlTO xjuEwnQHvqIHVWkGVCu59jRsq0FbXC1D92UYjL01aSUNTezmI+VDthy3a6JYKzgdTCZs vGShoYY8+kaQkyWIJTtQh9RrD9EsLWvdRBOVrfKV/pi9TEGI7FT0BcZ/68r/tHiLD++D 8TFg== X-Gm-Message-State: AOJu0Yxa+37HmthaJSoD3+GpAaTY4qKMlzL8HSRvO+ESxg7taWz+adv7 W9XwWBp082tvfFKtT9w5IzKC X-Google-Smtp-Source: AGHT+IHcsOCNu/zee5WBKu3EK5o4iNEZ0IEpDkI4h7bh30YLGN8qnSHVqBCOrPfu8WIhySgin6mEMQ== X-Received: by 2002:a17:907:9488:b0:9de:b20c:be46 with SMTP id dm8-20020a170907948800b009deb20cbe46mr3416693ejc.3.1699521018988; Thu, 09 Nov 2023 01:10:18 -0800 (PST) Received: from smtpclient.apple ([37.252.80.67]) by smtp.gmail.com with ESMTPSA id lt24-20020a170906fa9800b0099d798a6bb5sm2267449ejb.67.2023.11.09.01.10.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2023 01:10:17 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: PING^1 [PATCH v3] sched: Change no_real_insns_p to no_real_nondebug_insns_p [PR108273] From: Maxim Kuvyrkov In-Reply-To: Date: Thu, 9 Nov 2023 13:10:05 +0400 Cc: GCC Patches , Richard Guenther , Richard Sandiford , Jeff Law , Vladimir Makarov , Alexander Monakov , zhroma@ispras.ru, Andrey Belevantsev , Segher Boessenkool , Peter Bergner , Michael Meissner Content-Transfer-Encoding: quoted-printable Message-Id: <09FEFDAE-698B-4B06-A896-8088B9B31539@linaro.org> References: <85b4098e-a72f-d013-ff17-8097971f71ba@linux.ibm.com> To: "Kewen.Lin" X-Mailer: Apple Mail (2.3731.700.6) X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Kewen, Below are my comments. I don't want to override Alexander's review, and = if the patch looks good to him, it's fine to ignore my concerns. My main concern is that this adds a new entity -- forceful skipping of = DEBUG_INSN-only basic blocks -- to the scheduler for a somewhat minor = change in behavior. Unlike NOTEs and LABELs, DEBUG_INSNs are INSNS, and = there is already quite a bit of logic in the scheduler to skip them _as = part of normal operation_. Would you please consider 2 ideas below. #1: After a brief look, I'm guessing this part is causing the problem: haifa-sched.cc :schedule_block(): =3D=3D=3D [1] /* Loop until all the insns in BB are scheduled. */ while ((*current_sched_info->schedule_more_p) ()) { perform_replacements_new_cycle (); do { start_clock_var =3D clock_var; clock_var++; advance_one_cycle (); =3D=3D=3D and then in the nested loop we have =3D=3D=3D [2] /* We don't want md sched reorder to even see debug isns, so = put them out right away. */ if (ready.n_ready && DEBUG_INSN_P (ready_element (&ready, 0)) && (*current_sched_info->schedule_more_p) ()) { while (ready.n_ready && DEBUG_INSN_P (ready_element = (&ready, 0))) { rtx_insn *insn =3D ready_remove_first (&ready); gcc_assert (DEBUG_INSN_P (insn)); (*current_sched_info->begin_schedule_ready) (insn); scheduled_insns.safe_push (insn); last_scheduled_insn =3D insn; advance =3D schedule_insn (insn); gcc_assert (advance =3D=3D 0); if (ready.n_ready > 0) ready_sort (&ready); } } =3D=3D=3D . At the [1] point we already have sorted ready list, and I don't see = any blockers to doing [2] before calling advance_one_cycle(). #2 Another approach, which might be even easier, is to save the state of = DFA before the initial advance_one_cycle(), and then restore it if no = real insns have been scheduled. Kind regards, -- Maxim Kuvyrkov https://www.linaro.org > On Nov 8, 2023, at 06:49, Kewen.Lin wrote: >=20 > Hi, >=20 > Gentle ping this: >=20 > https://gcc.gnu.org/pipermail/gcc-patches/2023-October/634201.html >=20 > BR, > Kewen >=20 > on 2023/10/25 10:45, Kewen.Lin wrote: >> Hi, >>=20 >> This is almost a repost for v2 which was posted at[1] in March >> excepting for: >> 1) rebased from r14-4810 which is relatively up-to-date, >> some conflicts on "int to bool" return type change have >> been resolved; >> 2) adjust commit log a bit; >> 3) fix misspelled "articial" with "artificial" somewhere; >>=20 >> -- >> *v2 comments*: >>=20 >> By addressing Alexander's comments, against v1 this >> patch v2 mainly: >>=20 >> - Rename no_real_insns_p to no_real_nondebug_insns_p; >> - Introduce enum rgn_bb_deps_free_action for three >> kinds of actions to free deps; >> - Change function free_deps_for_bb_no_real_insns_p to >> resolve_forw_deps which only focuses on forward deps; >> - Extend the handlings to cover dbg-cnt sched_block, >> add one test case for it; >> - Move free_trg_info call in schedule_region to an >> appropriate place. >>=20 >> One thing I'm not sure about is the change in function >> sched_rgn_local_finish, currently the invocation to >> sched_rgn_local_free is guarded with !sel_sched_p (), >> so I just follow it, but the initialization of those >> structures (in sched_rgn_local_init) isn't guarded >> with !sel_sched_p (), it looks odd. >>=20 >> -- >>=20 >> As PR108273 shows, when there is one block which only has >> NOTE_P and LABEL_P insns at non-debug mode while has some >> extra DEBUG_INSN_P insns at debug mode, after scheduling >> it, the DFA states would be different between debug mode >> and non-debug mode. Since at non-debug mode, the block >> meets no_real_insns_p, it gets skipped; while at debug >> mode, it gets scheduled, even it only has NOTE_P, LABEL_P >> and DEBUG_INSN_P, the call of function advance_one_cycle >> will change the DFA state. PR108519 also shows this issue >> can be exposed by some scheduler changes. >>=20 >> This patch is to change function no_real_insns_p to >> function no_real_nondebug_insns_p by taking debug insn into >> account, which make us not try to schedule for the block >> having only NOTE_P, LABEL_P and DEBUG_INSN_P insns, >> resulting in consistent DFA states between non-debug and >> debug mode. >>=20 >> Changing no_real_insns_p to no_real_nondebug_insns_p caused >> ICE when doing free_block_dependencies, the root cause is >> that we create dependencies for debug insns, those >> dependencies are expected to be resolved during scheduling >> insns, but they get skipped after this change. >> By checking the code, it looks it's reasonable to skip to >> compute block dependences for no_real_nondebug_insns_p >> blocks. There is also another issue, which gets exposed >> in SPEC2017 bmks build at option -O2 -g, is that we could >> skip to schedule some block, which already gets dependency >> graph built so has dependencies computed and rgn_n_insns >> accumulated, then the later verification on if the graph >> becomes exhausted by scheduling would fail as follow: >>=20 >> /* Sanity check: verify that all region insns were >> scheduled. */ >> gcc_assert (sched_rgn_n_insns =3D=3D rgn_n_insns); >>=20 >> , and also some forward deps aren't resovled. >>=20 >> As Alexander pointed out, the current debug count handling >> also suffers the similar issue, so this patch handles these >> two cases together: one is for some block gets skipped by >> !dbg_cnt (sched_block), the other is for some block which >> is not no_real_nondebug_insns_p initially but becomes >> no_real_nondebug_insns_p due to speculative scheduling. >>=20 >> This patch can be bootstrapped and regress-tested on >> x86_64-redhat-linux, aarch64-linux-gnu and >> powerpc64{,le}-linux-gnu. >>=20 >> I also verified this patch can pass SPEC2017 both intrate >> and fprate bmks building at -g -O2/-O3. >>=20 >> Any thoughts? Is it ok for trunk? >>=20 >> [1] v2: = https://gcc.gnu.org/pipermail/gcc-patches/2023-March/614818.html >> [2] v1: = https://gcc.gnu.org/pipermail/gcc-patches/2023-March/614224.html >>=20 >> BR, >> Kewen >> ----- >> PR rtl-optimization/108273 >>=20 >> gcc/ChangeLog: >>=20 >> * haifa-sched.cc (no_real_insns_p): Rename to ... >> (no_real_nondebug_insns_p): ... this, and consider DEBUG_INSN_P insn. >> * sched-ebb.cc (schedule_ebb): Replace no_real_insns_p with >> no_real_nondebug_insns_p. >> * sched-int.h (no_real_insns_p): Rename to ... >> (no_real_nondebug_insns_p): ... this. >> * sched-rgn.cc (enum rgn_bb_deps_free_action): New enum. >> (bb_deps_free_actions): New static variable. >> (compute_block_dependences): Skip for no_real_nondebug_insns_p. >> (resolve_forw_deps): New function. >> (free_block_dependencies): Check bb_deps_free_actions and call >> function resolve_forw_deps for RGN_BB_DEPS_FREE_ARTIFICIAL. >> (compute_priorities): Replace no_real_insns_p with >> no_real_nondebug_insns_p. >> (schedule_region): Replace no_real_insns_p with >> no_real_nondebug_insns_p, set RGN_BB_DEPS_FREE_ARTIFICIAL if the = block >> get dependencies computed before but skipped now, fix up count >> sched_rgn_n_insns for it too. Call free_trg_info when the block >> gets scheduled, and move sched_rgn_local_finish after the loop >> of free_block_dependencies loop. >> (sched_rgn_local_init): Allocate and compute bb_deps_free_actions. >> (sched_rgn_local_finish): Free bb_deps_free_actions. >> * sel-sched.cc (sel_region_target_finish): Replace no_real_insns_p = with >> no_real_nondebug_insns_p. >>=20 >> gcc/testsuite/ChangeLog: >>=20 >> * gcc.target/powerpc/pr108273.c: New test. >> --- >> gcc/haifa-sched.cc | 9 +- >> gcc/sched-ebb.cc | 2 +- >> gcc/sched-int.h | 2 +- >> gcc/sched-rgn.cc | 148 = +++++++++++++++----- >> gcc/sel-sched.cc | 3 +- >> gcc/testsuite/gcc.target/powerpc/pr108273.c | 26 ++++ >> 6 files changed, 150 insertions(+), 40 deletions(-) >> create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108273.c >>=20 >> diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc >> index 8e8add709b3..30cc90ec49f 100644 >> --- a/gcc/haifa-sched.cc >> +++ b/gcc/haifa-sched.cc >> @@ -5033,14 +5033,17 @@ get_ebb_head_tail (basic_block beg, = basic_block end, >> *tailp =3D end_tail; >> } >>=20 >> -/* Return true if there are no real insns in the range [ HEAD, TAIL = ]. */ >> +/* Return true if there are no real nondebug insns in the range >> + [ HEAD, TAIL ]. */ >>=20 >> bool >> -no_real_insns_p (const rtx_insn *head, const rtx_insn *tail) >> +no_real_nondebug_insns_p (const rtx_insn *head, const rtx_insn = *tail) >> { >> while (head !=3D NEXT_INSN (tail)) >> { >> - if (!NOTE_P (head) && !LABEL_P (head)) >> + if (!NOTE_P (head) >> + && !LABEL_P (head) >> + && !DEBUG_INSN_P (head)) >> return false; >> head =3D NEXT_INSN (head); >> } >> diff --git a/gcc/sched-ebb.cc b/gcc/sched-ebb.cc >> index 110fcdbca4d..03d96290a7c 100644 >> --- a/gcc/sched-ebb.cc >> +++ b/gcc/sched-ebb.cc >> @@ -491,7 +491,7 @@ schedule_ebb (rtx_insn *head, rtx_insn *tail, = bool modulo_scheduling) >> first_bb =3D BLOCK_FOR_INSN (head); >> last_bb =3D BLOCK_FOR_INSN (tail); >>=20 >> - if (no_real_insns_p (head, tail)) >> + if (no_real_nondebug_insns_p (head, tail)) >> return BLOCK_FOR_INSN (tail); >>=20 >> gcc_assert (INSN_P (head) && INSN_P (tail)); >> diff --git a/gcc/sched-int.h b/gcc/sched-int.h >> index 64a2f0bcff9..adca494ade5 100644 >> --- a/gcc/sched-int.h >> +++ b/gcc/sched-int.h >> @@ -1397,7 +1397,7 @@ extern void free_global_sched_pressure_data = (void); >> extern int haifa_classify_insn (const_rtx); >> extern void get_ebb_head_tail (basic_block, basic_block, >> rtx_insn **, rtx_insn **); >> -extern bool no_real_insns_p (const rtx_insn *, const rtx_insn *); >> +extern bool no_real_nondebug_insns_p (const rtx_insn *, const = rtx_insn *); >>=20 >> extern int insn_sched_cost (rtx_insn *); >> extern int dep_cost_1 (dep_t, dw_t); >> diff --git a/gcc/sched-rgn.cc b/gcc/sched-rgn.cc >> index e5964f54ead..2549e834aa8 100644 >> --- a/gcc/sched-rgn.cc >> +++ b/gcc/sched-rgn.cc >> @@ -213,6 +213,22 @@ static int rgn_nr_edges; >> /* Array of size rgn_nr_edges. */ >> static edge *rgn_edges; >>=20 >> +/* Possible actions for dependencies freeing. */ >> +enum rgn_bb_deps_free_action >> +{ >> + /* This block doesn't get dependencies computed so don't need to = free. */ >> + RGN_BB_DEPS_FREE_NO, >> + /* This block gets scheduled normally so free dependencies as = usual. */ >> + RGN_BB_DEPS_FREE_NORMAL, >> + /* This block gets skipped in scheduling but has dependencies = computed early, >> + need to free the forward list artificially. */ >> + RGN_BB_DEPS_FREE_ARTIFICIAL >> +}; >> + >> +/* For basic block i, bb_deps_free_actions[i] indicates which action = needs >> + to be taken for freeing its dependencies. */ >> +static enum rgn_bb_deps_free_action *bb_deps_free_actions; >> + >> /* Mapping from each edge in the graph to its number in the rgn. */ >> #define EDGE_TO_BIT(edge) ((int)(size_t)(edge)->aux) >> #define SET_EDGE_TO_BIT(edge,nr) ((edge)->aux =3D (void = *)(size_t)(nr)) >> @@ -2735,6 +2751,15 @@ compute_block_dependences (int bb) >> gcc_assert (EBB_FIRST_BB (bb) =3D=3D EBB_LAST_BB (bb)); >> get_ebb_head_tail (EBB_FIRST_BB (bb), EBB_LAST_BB (bb), &head, = &tail); >>=20 >> + /* Don't compute block dependences if there are no real nondebug = insns. */ >> + if (no_real_nondebug_insns_p (head, tail)) >> + { >> + if (current_nr_blocks > 1) >> + propagate_deps (bb, &tmp_deps); >> + free_deps (&tmp_deps); >> + return; >> + } >> + >> sched_analyze (&tmp_deps, head, tail); >>=20 >> add_branch_dependences (head, tail); >> @@ -2749,6 +2774,24 @@ compute_block_dependences (int bb) >> targetm.sched.dependencies_evaluation_hook (head, tail); >> } >>=20 >> +/* Artificially resolve forward dependencies for instructions HEAD = to TAIL. */ >> + >> +static void >> +resolve_forw_deps (rtx_insn *head, rtx_insn *tail) >> +{ >> + rtx_insn *insn; >> + rtx_insn *next_tail =3D NEXT_INSN (tail); >> + sd_iterator_def sd_it; >> + dep_t dep; >> + >> + /* There could be some insns which get skipped in scheduling but = we compute >> + dependencies for them previously, so make them resolved. */ >> + for (insn =3D head; insn !=3D next_tail; insn =3D NEXT_INSN = (insn)) >> + for (sd_it =3D sd_iterator_start (insn, SD_LIST_FORW); >> + sd_iterator_cond (&sd_it, &dep);) >> + sd_resolve_dep (sd_it); >> +} >> + >> /* Free dependencies of instructions inside BB. */ >> static void >> free_block_dependencies (int bb) >> @@ -2758,9 +2801,12 @@ free_block_dependencies (int bb) >>=20 >> get_ebb_head_tail (EBB_FIRST_BB (bb), EBB_LAST_BB (bb), &head, = &tail); >>=20 >> - if (no_real_insns_p (head, tail)) >> + if (bb_deps_free_actions[bb] =3D=3D RGN_BB_DEPS_FREE_NO) >> return; >>=20 >> + if (bb_deps_free_actions[bb] =3D=3D RGN_BB_DEPS_FREE_ARTIFICIAL) >> + resolve_forw_deps (head, tail); >> + >> sched_free_deps (head, tail, true); >> } >>=20 >> @@ -3024,7 +3070,7 @@ compute_priorities (void) >> gcc_assert (EBB_FIRST_BB (bb) =3D=3D EBB_LAST_BB (bb)); >> get_ebb_head_tail (EBB_FIRST_BB (bb), EBB_LAST_BB (bb), &head, = &tail); >>=20 >> - if (no_real_insns_p (head, tail)) >> + if (no_real_nondebug_insns_p (head, tail)) >> continue; >>=20 >> rgn_n_insns +=3D set_priorities (head, tail); >> @@ -3158,7 +3204,7 @@ schedule_region (int rgn) >>=20 >> get_ebb_head_tail (first_bb, last_bb, &head, &tail); >>=20 >> - if (no_real_insns_p (head, tail)) >> + if (no_real_nondebug_insns_p (head, tail)) >> { >> gcc_assert (first_bb =3D=3D last_bb); >> continue; >> @@ -3178,44 +3224,62 @@ schedule_region (int rgn) >>=20 >> get_ebb_head_tail (first_bb, last_bb, &head, &tail); >>=20 >> - if (no_real_insns_p (head, tail)) >> + if (no_real_nondebug_insns_p (head, tail)) >> { >> gcc_assert (first_bb =3D=3D last_bb); >> save_state_for_fallthru_edge (last_bb, bb_state[first_bb->index]); >> - continue; >> + >> + if (bb_deps_free_actions[bb] =3D=3D RGN_BB_DEPS_FREE_NO) >> + continue; >> + >> + /* As it's not no_real_nondebug_insns_p initially, then it has = some >> + dependencies computed so free it artificially. */ >> + bb_deps_free_actions[bb] =3D RGN_BB_DEPS_FREE_ARTIFICIAL; >> } >> + else >> + { >> + current_sched_info->prev_head =3D PREV_INSN (head); >> + current_sched_info->next_tail =3D NEXT_INSN (tail); >>=20 >> - current_sched_info->prev_head =3D PREV_INSN (head); >> - current_sched_info->next_tail =3D NEXT_INSN (tail); >> + remove_notes (head, tail); >>=20 >> - remove_notes (head, tail); >> + unlink_bb_notes (first_bb, last_bb); >>=20 >> - unlink_bb_notes (first_bb, last_bb); >> + target_bb =3D bb; >>=20 >> - target_bb =3D bb; >> + gcc_assert (flag_schedule_interblock || current_nr_blocks =3D=3D = 1); >> + current_sched_info->queue_must_finish_empty =3D current_nr_blocks = =3D=3D 1; >>=20 >> - gcc_assert (flag_schedule_interblock || current_nr_blocks =3D=3D= 1); >> - current_sched_info->queue_must_finish_empty =3D = current_nr_blocks =3D=3D 1; >> + curr_bb =3D first_bb; >> + if (dbg_cnt (sched_block)) >> + { >> + int saved_last_basic_block =3D last_basic_block_for_fn (cfun); >>=20 >> - curr_bb =3D first_bb; >> - if (dbg_cnt (sched_block)) >> - { >> - int saved_last_basic_block =3D last_basic_block_for_fn (cfun); >> + schedule_block (&curr_bb, bb_state[first_bb->index]); >> + gcc_assert (EBB_FIRST_BB (bb) =3D=3D first_bb); >> + sched_rgn_n_insns +=3D sched_n_insns; >> + realloc_bb_state_array (saved_last_basic_block); >> + save_state_for_fallthru_edge (last_bb, curr_state); >>=20 >> - schedule_block (&curr_bb, bb_state[first_bb->index]); >> - gcc_assert (EBB_FIRST_BB (bb) =3D=3D first_bb); >> - sched_rgn_n_insns +=3D sched_n_insns; >> - realloc_bb_state_array (saved_last_basic_block); >> - save_state_for_fallthru_edge (last_bb, curr_state); >> - } >> - else >> - { >> - sched_rgn_n_insns +=3D rgn_n_insns; >> - } >> + /* Clean up. */ >> + if (current_nr_blocks > 1) >> + free_trg_info (); >> + } >> + else >> + bb_deps_free_actions[bb] =3D RGN_BB_DEPS_FREE_ARTIFICIAL; >> + } >>=20 >> - /* Clean up. */ >> - if (current_nr_blocks > 1) >> - free_trg_info (); >> + /* We have counted this block when computing rgn_n_insns >> + previously, so need to fix up sched_rgn_n_insns now. */ >> + if (bb_deps_free_actions[bb] =3D=3D = RGN_BB_DEPS_FREE_ARTIFICIAL) >> + { >> + while (head !=3D NEXT_INSN (tail)) >> + { >> + if (INSN_P (head)) >> + sched_rgn_n_insns++; >> + head =3D NEXT_INSN (head); >> + } >> + } >> } >>=20 >> /* Sanity check: verify that all region insns were scheduled. */ >> @@ -3223,13 +3287,13 @@ schedule_region (int rgn) >>=20 >> sched_finish_ready_list (); >>=20 >> - /* Done with this region. */ >> - sched_rgn_local_finish (); >> - >> /* Free dependencies. */ >> for (bb =3D 0; bb < current_nr_blocks; ++bb) >> free_block_dependencies (bb); >>=20 >> + /* Done with this region. */ >> + sched_rgn_local_finish (); >> + >> gcc_assert (haifa_recovery_bb_ever_added_p >> || deps_pools_are_empty_p ()); >> } >> @@ -3450,6 +3514,19 @@ sched_rgn_local_init (int rgn) >> e->aux =3D NULL; >> } >> } >> + >> + /* Initialize bb_deps_free_actions. */ >> + bb_deps_free_actions >> + =3D XNEWVEC (enum rgn_bb_deps_free_action, current_nr_blocks); >> + for (bb =3D 0; bb < current_nr_blocks; bb++) >> + { >> + rtx_insn *head, *tail; >> + get_ebb_head_tail (EBB_FIRST_BB (bb), EBB_LAST_BB (bb), &head, = &tail); >> + if (no_real_nondebug_insns_p (head, tail)) >> + bb_deps_free_actions[bb] =3D RGN_BB_DEPS_FREE_NO; >> + else >> + bb_deps_free_actions[bb] =3D RGN_BB_DEPS_FREE_NORMAL; >> + } >> } >>=20 >> /* Free data computed for the finished region. */ >> @@ -3467,9 +3544,12 @@ sched_rgn_local_free (void) >> void >> sched_rgn_local_finish (void) >> { >> - if (current_nr_blocks > 1 && !sel_sched_p ()) >> + if (!sel_sched_p ()) >> { >> - sched_rgn_local_free (); >> + if (current_nr_blocks > 1) >> + sched_rgn_local_free (); >> + >> + free (bb_deps_free_actions); >> } >> } >>=20 >> diff --git a/gcc/sel-sched.cc b/gcc/sel-sched.cc >> index 1925f4a9461..8310c892e13 100644 >> --- a/gcc/sel-sched.cc >> +++ b/gcc/sel-sched.cc >> @@ -7213,7 +7213,8 @@ sel_region_target_finish (bool = reset_sched_cycles_p) >>=20 >> find_ebb_boundaries (EBB_FIRST_BB (i), scheduled_blocks); >>=20 >> - if (no_real_insns_p (current_sched_info->head, = current_sched_info->tail)) >> + if (no_real_nondebug_insns_p (current_sched_info->head, >> + current_sched_info->tail)) >> continue; >>=20 >> if (reset_sched_cycles_p) >> diff --git a/gcc/testsuite/gcc.target/powerpc/pr108273.c = b/gcc/testsuite/gcc.target/powerpc/pr108273.c >> new file mode 100644 >> index 00000000000..937224eaa69 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/powerpc/pr108273.c >> @@ -0,0 +1,26 @@ >> +/* { dg-options "-O2 -fdbg-cnt=3Dsched_block:1" } */ >> +/* { dg-prune-output {\*\*\*dbgcnt:.*limit.*reached} } */ >> + >> +/* Verify there is no ICE. */ >> + >> +int a, b, c, e, f; >> +float d; >> + >> +void >> +g () >> +{ >> + float h, i[1]; >> + for (; f;) >> + if (c) >> + { >> + d *e; >> + if (b) >> + { >> + float *j =3D i; >> + j[0] +=3D 0; >> + } >> + h +=3D d; >> + } >> + if (h) >> + a =3D i[0]; >> +} >> -- >> 2.39.1