From b392d3ac27be026feab32da0d803a229b52c812d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pavel=20Ondra=C4=8Dka?= Date: Fri, 23 Jun 2023 10:39:16 +0200 Subject: [PATCH] r300: assert that every writer has a reader Dead writes can lead to problems with regalloc, so add a safety assert to catch such cases in the vertex shaders at least in the meantime. Additionally we could think there are no readers due to some shortcoming of out dataflow analysis or some other bug which we would also like to know about. Reviewed-by: Filip Gawin Part-of: --- src/gallium/drivers/r300/compiler/radeon_variable.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/r300/compiler/radeon_variable.c b/src/gallium/drivers/r300/compiler/radeon_variable.c index c07b20a..30e1232 100644 --- a/src/gallium/drivers/r300/compiler/radeon_variable.c +++ b/src/gallium/drivers/r300/compiler/radeon_variable.c @@ -401,7 +401,19 @@ struct rc_list * rc_get_variables(struct radeon_compiler * c) memset(&reader_data, 0, sizeof(reader_data)); rc_get_readers(c, inst, &reader_data, NULL, NULL, NULL); if (reader_data.ReaderCount == 0) { - continue; + /* Variable is only returned if there is both writer + * and reader. This means dead writes will not get + * register allocated as a result and can overwrite random + * registers. Assert on dead writes insted so we can improve + * the DCE. + */ + const struct rc_opcode_info *opcode = + rc_get_opcode_info(inst->U.I.Opcode); + assert(c->type == RC_FRAGMENT_PROGRAM || + !opcode->HasDstReg || + inst->U.I.DstReg.File == RC_FILE_OUTPUT || + inst->U.I.DstReg.File == RC_FILE_ADDRESS); + continue; } new_var = rc_variable(c, inst->U.I.DstReg.File, inst->U.I.DstReg.Index, -- 2.7.4