[Mesa-dev] [PATCH 2/5] i965/cfg: Track prev_block and prev_inst explicitly in the whole function
Francisco Jerez
currojerez at riseup.net
Wed Mar 16 17:22:23 UTC 2016
Ian Romanick <idr at freedesktop.org> writes:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> This provides a trivial simplification now, and it makes some future
> changes more straight forward.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
> src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp b/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp
> index 716e2bc..7aa72b1 100644
> --- a/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp
> @@ -41,7 +41,9 @@ dead_control_flow_eliminate(backend_shader *s)
> bool progress = false;
>
> foreach_block_safe (block, s->cfg) {
> + bblock_t *prev_block = block->prev();
> backend_instruction *const inst = block->start();
> + backend_instruction *prev_inst = prev_block->end();
>
Just noticed that this change is bogus when 'block' is the first block
of the program: block->prev() will return an incorrectly casted pointer
to the head sentinel and prev_block->end() will then read invalid
memory.
Any suggestions?
> /* ENDIF instructions, by definition, can only be found at the start of
> * basic blocks.
> @@ -52,20 +54,20 @@ dead_control_flow_eliminate(backend_shader *s)
> backend_instruction *endif_inst = inst;
>
> backend_instruction *if_inst = NULL, *else_inst = NULL;
> - backend_instruction *prev_inst = endif_block->prev()->end();
> if (prev_inst->opcode == BRW_OPCODE_ELSE) {
> else_inst = prev_inst;
> else_block = endif_block->prev();
> found = true;
>
> - if (else_block->start_ip == else_block->end_ip)
> - prev_inst = else_block->prev()->end();
> + if (else_block->start_ip == else_block->end_ip) {
> + prev_block = prev_block->prev();
> + prev_inst = prev_block->end();
> + }
> }
>
> if (prev_inst->opcode == BRW_OPCODE_IF) {
> if_inst = prev_inst;
> - if_block = else_block != NULL ? else_block->prev()
> - : endif_block->prev();
> + if_block = prev_block;
> found = true;
> } else {
> /* Don't remove the ENDIF if we didn't find a dead IF. */
> --
> 2.5.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 212 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160316/ede3c78c/attachment.sig>
More information about the mesa-dev
mailing list