Mesa (main): nir: Add a correctness note for nir_lower_phis_to_regs_block

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue May 31 14:43:49 UTC 2022


Module: Mesa
Branch: main
Commit: eb0d571ce42b1232bd35b5126bd09a333cd8a0cf
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb0d571ce42b1232bd35b5126bd09a333cd8a0cf

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Mon May 30 18:57:58 2022 -0500

nir: Add a correctness note for nir_lower_phis_to_regs_block

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16111>

---

 src/compiler/nir/nir_from_ssa.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_from_ssa.c b/src/compiler/nir/nir_from_ssa.c
index 9ad45cb1a8c..3bcac93302c 100644
--- a/src/compiler/nir/nir_from_ssa.c
+++ b/src/compiler/nir/nir_from_ssa.c
@@ -974,7 +974,22 @@ place_phi_read(nir_builder *b, nir_register *reg,
  * single block to convert all of its phis to a register and some movs.
  * The code that is generated, while not optimal for actual codegen in a
  * back-end, is easy to generate, correct, and will turn into the same set of
- * phis after you call regs_to_ssa and do some copy propagation.
+ * phis after you call regs_to_ssa and do some copy propagation.  For each phi
+ * node we do the following:
+ *
+ *  1. For each phi instruction in the block, create a new nir_register
+ *
+ *  2. Insert movs at the top of the destination block for each phi and
+ *     rewrite all uses of the phi to use the mov.
+ *
+ *  3. For each phi source, insert movs in the predecessor block from the phi
+ *     source to the register associated with the phi.
+ *
+ * Correctness is guaranteed by the fact that we create a new register for
+ * each phi and emit movs on both sides of the control-flow edge.  Because all
+ * the phis have SSA destinations (we assert this) and there is a separate
+ * temporary for each phi, all movs inserted in any particular block have
+ * unique destinations so the order of operations does not matter.
  *
  * The one intelligent thing this pass does is that it places the moves from
  * the phi sources as high up the predecessor tree as possible instead of in



More information about the mesa-commit mailing list