From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C5BA23858409; Mon, 12 Jun 2023 09:23:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5BA23858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686561805; bh=w4QNgr/Wzeq1zTyCK+jOJwNUwepsAzS93FXowb8MNUc=; h=From:To:Subject:Date:From; b=WElC9lZOTAX21bNJD6fvU/57CXRzz7AiwTIeJqaum8y4iZ9KBbrNhnLawHZyR1qme x95/fCaLFcLi7t7onTL4eCnFvZy++/V8164Es7woWjC/2xOmzl1R1pKjjfeCcz7iTU 1thhYWyaTPt+MjTpJHeH3UG8N7MXSs5nbL25greY= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110218] New: sink pass heuristic not working in practice Date: Mon, 12 Jun 2023 09:23:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110218 Bug ID: 110218 Summary: sink pass heuristic not working in practice Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- In r0-112722-g1cc17820c32e8b Jeff introduced --param sink-frequency-thresho= ld replacing - /* Move the expression to a post dominator can't reduce the number of - executions. */ - if (dominated_by_p (CDI_POST_DOMINATORS, frombb, sinkbb)) - return false; with /* If BEST_BB is at the same nesting level, then require it to have significantly lower execution frequency to avoid gratuitous movement. = */ if (bb_loop_depth (best_bb) =3D=3D bb_loop_depth (early_bb) /* If result of comparsion is unknown, prefer EARLY_BB. Thus use !(...>=3D..) rather than (...<...) */ && !(best_bb->count * 100 >=3D early_bb->count * threshold)) return best_bb; where the logic of course is that when best_bb post-dominates early_bb then the counts should be the same. Other than that the new logic prevents some partial dead code elimination. What the sinking pass does is, in addition to moving code to only conditional executed places, it performs scheduling by moving the code to the latest "best" basic block, not the earliest candidate. The above logic might also catch EH and error control flow, avoiding sinking along effective fallthru edges. But rather than applying this only at the end we should at least consider doing it in a loop walking the dominators similar to the one selecting the best candidate while (temp_bb !=3D early_bb) { /* If we've moved into a lower loop nest, then that becomes our best block. */ if (bb_loop_depth (temp_bb) < bb_loop_depth (best_bb)) best_bb =3D temp_bb; /* Walk up the dominator tree, hopefully we'll find a shallower loop nest. */ temp_bb =3D get_immediate_dominator (CDI_DOMINATORS, temp_bb); } I'm seeing guessed profile where the dominated block has higher count than the dominating block ... Where to sink a stmt to in an effectively (ignoring error paths) post-dominance region is a scheduling and register pressure problem where also call ABI (in case of EH) matters. Arguably that's none of GIMPLEs business.=