r300: assert that every writer has a reader
authorPavel Ondračka <pavel.ondracka@gmail.com>
Fri, 23 Jun 2023 08:39:16 +0000 (10:39 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 5 Jul 2023 18:34:37 +0000 (18:34 +0000)
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 <filip.gawin@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23927>

src/gallium/drivers/r300/compiler/radeon_variable.c

index c07b20a..30e1232 100644 (file)
@@ -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,