From eb0d571ce42b1232bd35b5126bd09a333cd8a0cf Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 30 May 2022 18:57:58 -0500 Subject: [PATCH] nir: Add a correctness note for nir_lower_phis_to_regs_block Reviewed-by: Alyssa Rosenzweig Part-of: --- 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