[spirv-reader][ir] Fix premerge calculation.

When determining the premerge block for an `if` instruction, make sure
we don't select a walk stop block (like a `merge` instruction). This
block can't be a premerge block as it has to come after the `if` merge
block itself.

Change-Id: I973fde66cf790d002562dcf19021d35462c8c4f4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/245335
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/spirv/reader/parser/branch_test.cc b/src/tint/lang/spirv/reader/parser/branch_test.cc
index 566c562..a0d7b17 100644
--- a/src/tint/lang/spirv/reader/parser/branch_test.cc
+++ b/src/tint/lang/spirv/reader/parser/branch_test.cc
@@ -520,21 +520,21 @@
  %main_start = OpLabel
                OpBranch %10
          %10 = OpLabel
-               OpLoopMerge %merge %cont None
+               OpLoopMerge %99 %80 None
                OpBranch %20
          %20 = OpLabel
         %foo = OpIAdd %i32 %one %two
                OpSelectionMerge %50 None
                OpBranchConditional %true %30 %40
          %30 = OpLabel
-               OpBranch %merge
+               OpBranch %99
          %40 = OpLabel
-               OpBranch %merge
+               OpBranch %99
          %50 = OpLabel
                OpUnreachable
-       %cont = OpLabel
+         %80 = OpLabel
                OpBranch %10
-      %merge = OpLabel
+         %99 = OpLabel
        %foo2 = OpCopyObject %i32 %foo
                OpReturn
                OpFunctionEnd
@@ -553,22 +553,13 @@
             exit_loop %3  # loop_1
           }
         }
-        if true [t: $B6, f: $B7] {  # if_2
-          $B6: {  # true
-            %4:i32 = let %3
-            ret
-          }
-          $B7: {  # false
-            unreachable
-          }
-        }
         unreachable
       }
       $B3: {  # continuing
         next_iteration  # -> $B2
       }
     }
-    %5:i32 = let %2
+    %4:i32 = let %2
     ret
   }
 }
diff --git a/src/tint/lang/spirv/reader/parser/parser.cc b/src/tint/lang/spirv/reader/parser/parser.cc
index 7801b9c..fe9c4e8 100644
--- a/src/tint/lang/spirv/reader/parser/parser.cc
+++ b/src/tint/lang/spirv/reader/parser/parser.cc
@@ -1851,6 +1851,11 @@
             true_blocks.pop_back();
             false_blocks.pop_back();
         }
+
+        // If this is already a stop block, so it can't be a premerge
+        if (id.has_value() && walk_stop_blocks_.contains(id.value())) {
+            return std::nullopt;
+        }
         return id;
     }