nir/spirv: return after emitting a branch in block
authorJuan A. Suarez Romero <jasuarez@igalia.com>
Wed, 27 Feb 2019 10:42:00 +0000 (10:42 +0000)
committerJuan A. Suarez Romero <jasuarez@igalia.com>
Thu, 28 Feb 2019 08:47:06 +0000 (09:47 +0100)
When emitting a branch in a block, it does not make sense to continue
processing further instructions, as they will not be reachable.

This fixes a nasty case with a loop with a branch that both then-part
and else-part exits the loop:

%1 = OpLabel
     OpLoopMerge %2 %3 None
     OpBranchConditional %false %2 %2
%3 = OpLabel
     OpBranch %1
%2 = OpLabel
    [...]

We know that block %1 will branch always to block %2, which is the merge
block for the loop. And thus a break is emitted. If we keep continuing
processing further instructions, we will be processing the branch
conditional and thus emitting the proper NIR conditional, which leads to
instructions after the break.

This fixes dEQP-VK.graphicsfuzz.continue-and-merge.

CC: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/spirv/vtn_cfg.c

index c32d54e9006fef2b3998df479b2cce4bcfe2b88e..7868eeb60bc986c8ac4b4123dbd1bd783833c2e5 100644 (file)
@@ -916,6 +916,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list,
          if (block->branch_type != vtn_branch_type_none) {
             vtn_emit_branch(b, block->branch_type,
                             switch_fall_var, has_switch_break);
+            return;
          }
 
          break;