broadcom/compiler: fix assert that current instruction must be in current block

This was not considering the possibility that the driver has called
nir_before_block() or nir_after_block() to update the cursor, in which
case the cursor link points to the instruction list header and not
to an actual instruction.

Fixes incorrect debug-assert crash in:
dEQP-VK.graphicsfuzz.cov-increment-vector-component-with-matrix-copy

Fixes: 265515fa62 ("broadcom/compiler: check instruction belongs to current block")
Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13467>
(cherry picked from commit 1561d0126a)
This commit is contained in:
Iago Toral Quiroga 2021-10-21 11:35:28 +02:00 committed by Eric Engestrom
parent fa24bfb914
commit 664cc248b3
2 changed files with 6 additions and 3 deletions

View file

@ -841,7 +841,7 @@
"description": "broadcom/compiler: fix assert that current instruction must be in current block",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "265515fa62664eac006dcff278ed549c75863b79"
},

View file

@ -1873,7 +1873,10 @@ try_opt_ldunif(struct v3d_compile *c, uint32_t index, struct qreg *unif)
assert(c->cur_block);
#ifdef DEBUG
/* Check if the current instruction is part of the current block */
/* We can only reuse a uniform if it was emitted in the same block,
* so callers must make sure the current instruction is being emitted
* in the current block.
*/
bool found = false;
vir_for_each_inst(inst, c->cur_block) {
if (&inst->link == c->cursor.link) {
@ -1882,7 +1885,7 @@ try_opt_ldunif(struct v3d_compile *c, uint32_t index, struct qreg *unif)
}
}
assert(found || list_is_empty(&c->cur_block->instructions));
assert(found || &c->cur_block->instructions == c->cursor.link);
#endif
list_for_each_entry_from_rev(struct qinst, inst, c->cursor.link->prev,