From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id D47AB3858D1E; Mon, 1 May 2023 17:44:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D47AB3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682963081; bh=lUyvXvY8/SYAK+qyPmU2wYKW4x6c+TJmOKZo15VrD3o=; h=From:To:Subject:Date:From; b=oq7XhprPY+k6EjO1eRwAT4xMM9wYH1P2pH+WbsQTZXBeK5TtUkYkUrP3t/pKm4Q/a a5uVXlYnXyaETfx3/DrL9ncP85ty5ILxLHi7Is1PdTSp2wq57CQCupugJjfgTOYao+ fen6BwmOLt2iXU66Qj4HlWKuGM+liUa/Hc81FRsc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-385] PHIOPT: Update comment about what the pass now does X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 977a3be3ccbc7f177316b2b349523023cac37bcd X-Git-Newrev: d89b152436a14cae3715af06cd52ed2d0eaafb8e Message-Id: <20230501174441.D47AB3858D1E@sourceware.org> Date: Mon, 1 May 2023 17:44:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d89b152436a14cae3715af06cd52ed2d0eaafb8e commit r14-385-gd89b152436a14cae3715af06cd52ed2d0eaafb8e Author: Andrew Pinski Date: Mon May 1 09:21:59 2023 -0700 PHIOPT: Update comment about what the pass now does I noticed I didn't update the comment about how the pass works after I initially added match_simplify_replacement. Anyways this updates the comment to be the current state of the pass. OK? gcc/ChangeLog: * tree-ssa-phiopt.cc: Update comment about how the transformation are implemented. Diff: --- gcc/tree-ssa-phiopt.cc | 67 +++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 006c56fe4aa..de3d1ddd279 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -3685,31 +3685,55 @@ gate_hoist_loads (void) } /* This pass tries to replaces an if-then-else block with an - assignment. We have four kinds of transformations. Some of these - transformations are also performed by the ifcvt RTL optimizer. + assignment. We have different kinds of transformations. + Some of these transformations are also performed by the ifcvt + RTL optimizer. - Conditional Replacement + PHI-OPT using Match-and-simplify infrastructure ----------------------- - This transformation, implemented in match_simplify_replacement, - replaces + The PHI-OPT pass will try to use match-and-simplify infrastructure + (gimple_simplify) to do transformations. This is implemented in + match_simplify_replacement. + The way it works is it replaces: bb0: if (cond) goto bb2; else goto bb1; bb1: bb2: - x = PHI <0 (bb1), 1 (bb0), ...>; + x = PHI ; - with + with a statement if it gets simplified from `cond ? b : a`. bb0: - x' = cond; - goto bb2; + x1 = cond ? b : a; bb2: - x = PHI ; + x = PHI ; + Bb1 might be removed as it becomes unreachable when doing the replacement. + Though bb1 does not have to be considered a forwarding basic block from bb0. + + Will try to see if `(!cond) ? a : b` gets simplified (iff !cond simplifies); + this is done not to have an explosion of patterns in match.pd. + Note bb1 does not need to be completely empty, it can contain + one statement which is known not to trap. - We remove bb1 as it becomes unreachable. This occurs often due to - gimplification of conditionals. + It also can handle the case where we have two forwarding bbs (diamond): + bb0: + if (cond) goto bb2; else goto bb1; + bb1: goto bb3; + bb2: goto bb3; + bb3: + x = PHI ; + And that is replaced with a statement if it is simplified + from `cond ? b : a`. + Again bb1 and bb2 does not have to be completely empty but + each can contain one statement which is known not to trap. + But in this case bb1/bb2 can only be forwarding basic blocks. + + This fully replaces the old "Conditional Replacement", + "ABS Replacement" transformations as they are now + implmeneted in match.pd. + Some parts of the "MIN/MAX Replacement" are re-implemented in match.pd. Value Replacement ----------------- @@ -3751,25 +3775,6 @@ gate_hoist_loads (void) t3 = t1 & t2; x = a; - ABS Replacement - --------------- - - This transformation, implemented in match_simplify_replacement, replaces - - bb0: - if (a >= 0) goto bb2; else goto bb1; - bb1: - x = -a; - bb2: - x = PHI ; - - with - - bb0: - x' = ABS_EXPR< a >; - bb2: - x = PHI ; - MIN/MAX Replacement -------------------