Mesa (master): spirv: repair ssa defs for switchs with only default case
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Apr 8 18:50:36 UTC 2021
Module: Mesa
Branch: master
Commit: 4220befb383112798b1afc1ba13419ed79470cba
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=4220befb383112798b1afc1ba13419ed79470cba
Author: Andrii Simiklit <andrii.simiklit at globallogic.com>
Date: Tue Nov 24 14:28:12 2020 +0200
spirv: repair ssa defs for switchs with only default case
This fixes OpSwitch corner case when switch doesn't have any targets
just a `default` and SSAs defined in it is used after switch block
directly without phis.
v2: Just use `repair_ssa` for all structured control-flow cases
( - Jason Ekstrand <jason at jlekstrand.net>
- Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com> )
Closes: #3787
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Signed-off-by: Andrii Simiklit <andrii.simiklit at globallogic.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7755>
---
src/compiler/spirv/vtn_cfg.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index 8d0794ed4af..dd91352bfbd 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -1393,12 +1393,22 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
nir_rematerialize_derefs_in_use_blocks_impl(impl);
- /* Continue blocks for loops get inserted before the body of the loop
- * but instructions in the continue may use SSA defs in the loop body.
- * Therefore, we need to repair SSA to insert the needed phi nodes.
+ /*
+ * There are some cases where we need to repair SSA to insert
+ * the needed phi nodes:
+ *
+ * - Continue blocks for loops get inserted before the body of the loop
+ * but instructions in the continue may use SSA defs in the loop body.
+ *
+ * - Early termination instructions `OpKill` and `OpTerminateInvocation`,
+ * in NIR. They're represented by regular intrinsics with no control-flow
+ * semantics. This means that the SSA form from the SPIR-V may not
+ * 100% match NIR.
+ *
+ * - Switches with only default case may also define SSA which may
+ * subsequently be used out of the switch.
*/
- if (func->nir_func->impl->structured &&
- (b->has_loop_continue || b->has_early_terminate))
+ if (func->nir_func->impl->structured)
nir_repair_ssa_impl(impl);
func->emitted = true;
More information about the mesa-commit
mailing list