Repository: aptos-labs/aptos-core (language: python)

Issue:
[compiler-v2] Match generates unverifiable code
Given the following:

```
module 0x815::m {
    enum Entity {
        Person { id: u64 },
        Institution { id: u64, admin: u64 }
    }

    fun id2(self: &Entity): u64 {
        match (self) {
            Person{id} if *id > 0 => *id,
            Institution{id, ..} => *id,
            _ => 0
        }
    }
}
```

... the compiler fails with verification failure:

```
bug: bytecode verification failed with unexpected status code `MOVELOC_UNAVAILABLE_ERROR`. This is a compiler bug, consider reporting it.
   ┌─ tests/match.move:17:9
   │
17 │ ╭         match (self) {
18 │ │             Person{id} if *id > 0 => *id,
19 │ │             Institution{id, ..} => *id,
20 │ │             _ => 0
21 │ │         }
   │ ╰─────────^

```


Discussion / hints:

Fix patch:
diff --git a/developer-docs b/developer-docs
new file mode 160000
index 0000000000000..e8bcac521a502
--- /dev/null
+++ b/developer-docs
@@ -0,0 +1,1 @@
+Subproject commit e8bcac521a502480fd6c55231fec657df0bfb953
diff --git a/third_party/move/move-compiler-v2/src/experiments.rs b/third_party/move/move-compiler-v2/src/experiments.rs
index ceea7b65d8403..f043564b6406f 100644
--- a/third_party/move/move-compiler-v2/src/experiments.rs
+++ b/third_party/move/move-compiler-v2/src/experiments.rs
@@ -146,7 +146,7 @@ pub static EXPERIMENTS: Lazy<BTreeMap<String, Experiment>> = Lazy::new(|| {
         Experiment {
             name: Experiment::SPLIT_CRITICAL_EDGES.to_string(),
             description: "Turns on or off splitting of critical edges".to_string(),
-            default: Given(false),
+            default: Given(true),
         },
         Experiment {
             name: Experiment::OPTIMIZE.to_string(),
diff --git a/third_party/move/move-compiler-v2/src/lib.rs b/third_party/move/move-compiler-v2/src/lib.rs
index ae0f454fc95e5..9f71c4871aba8 100644
--- a/third_party/move/move-compiler-v2/src/lib.rs
+++ b/third_party/move/move-compiler-v2/src/lib.rs
@@ -453,6 +453,12 @@ pub fn bytecode_pipeline(env: &GlobalEnv) -> FunctionTargetPipeline {
 
     if options.experiment_on(Experiment::CFG_SIMPLIFICATION) {
         pipeline.add_processor(Box::new(ControlFlowGraphSimplifier {}));
+        if options.experiment_on(Experiment::SPLIT_CRITICAL_EDGES) {
+            // Currently, CFG simplification can again introduce critical edges, so
+            // remove them. Notice that absence of critical edges is (theoretical) relevant
+            // for the livevar processor, which is used frequently below.
+            pipeline.add_processor(Box::new(SplitCriticalEdgesProcessor {}));
+        }
     }
 
     if options.experiment_on(Experiment::DEAD_CODE_ELIMINATION) {


Test patch:
diff --git a/third_party/move/move-compiler-v2/tests/control-flow-simplification/bug-10253.on.exp b/third_party/move/move-compiler-v2/tests/control-flow-simplification/bug-10253.on.exp
index b4ce4b4d8feaf..f5fce68026abf 100644
--- a/third_party/move/move-compiler-v2/tests/control-flow-simplification/bug-10253.on.exp
+++ b/third_party/move/move-compiler-v2/tests/control-flow-simplification/bug-10253.on.exp
@@ -290,23 +290,27 @@ B1:
 	7: MoveLoc[2](loc1: u64)
 	8: MoveLoc[3](loc2: u64)
 	9: Lt
-	10: BrFalse(18)
+	10: BrTrue(12)
 B2:
-	11: ImmBorrowLoc[0](Arg0: vector<u8>)
-	12: CopyLoc[1](loc0: u64)
-	13: VecImmBorrow(2)
-	14: ReadRef
-	15: LdU8(0)
-	16: Neq
-	17: BrFalse(19)
+	11: Branch(20)
 B3:
-	18: Ret
+	12: ImmBorrowLoc[0](Arg0: vector<u8>)
+	13: CopyLoc[1](loc0: u64)
+	14: VecImmBorrow(2)
+	15: ReadRef
+	16: LdU8(0)
+	17: Neq
+	18: BrFalse(21)
 B4:
-	19: MoveLoc[1](loc0: u64)
-	20: LdU64(1)
-	21: Add
-	22: StLoc[1](loc0: u64)
-	23: Branch(2)
+	19: Branch(20)
+B5:
+	20: Ret
+B6:
+	21: MoveLoc[1](loc0: u64)
+	22: LdU64(1)
+	23: Add
+	24: StLoc[1](loc0: u64)
+	25: Branch(2)
 }
 entry public guess_with_break_without_inline(Arg0: vector<u8>) /* def_idx: 2 */ {
 B0:
diff --git a/third_party/move/move-compiler-v2/tests/copy-propagation/branch_1.exp b/third_party/move/move-compiler-v2/tests/copy-propagation/branch_1.exp
index 79a1c285744db..3a436a82d1143 100644
--- a/third_party/move/move-compiler-v2/tests/copy-propagation/branch_1.exp
+++ b/third_party/move/move-compiler-v2/tests/copy-propagation/branch_1.exp
@@ -28,12 +28,14 @@ fun m::foo($t0: bool, $t1: u64): u64 {
      var $t4: u64
      var $t5: u64
   0: $t3 := move($t1)
-  1: if ($t0) goto 2 else goto 5
-  2: label L0
-  3: $t4 := 0
-  4: $t3 := move($t4)
-  5: label L2
-  6: $t5 := 1
-  7: $t2 := +($t3, $t5)
-  8: return $t2
+  1: if ($t0) goto 4 else goto 2
+  2: label L3
+  3: goto 7
+  4: label L0
+  5: $t4 := 0
+  6: $t3 := move($t4)
+  7: label L2
+  8: $t5 := 1
+  9: $t2 := +($t3, $t5)
+ 10: return $t2
 }
diff --git a/third_party/move/move-compiler-v2/tests/copy-propagation/bug_12068.exp b/third_party/move/move-compiler-v2/tests/copy-propagation/bug_12068.exp
index 18519e6c71026..fe2ed828da30d 100644
--- a/third_party/move/move-compiler-v2/tests/copy-propagation/bug_12068.exp
+++ b/third_party/move/move-compiler-v2/tests/copy-propagation/bug_12068.exp
@@ -49,18 +49,20 @@ fun m::main() {
      var $t6: u64
   0: $t0 := 0
   1: $t1 := true
-  2: if ($t1) goto 3 else goto 7
-  3: label L2
-  4: $t3 := 1
-  5: $t2 := +($t0, $t3)
-  6: $t0 := move($t2)
-  7: label L1
-  8: $t5 := 1
-  9: $t4 := ==($t0, $t5)
- 10: if ($t4) goto 11 else goto 13
- 11: label L5
- 12: return ()
- 13: label L6
- 14: $t6 := 42
- 15: abort($t6)
+  2: if ($t1) goto 5 else goto 3
+  3: label L7
+  4: goto 9
+  5: label L2
+  6: $t3 := 1
+  7: $t2 := +($t0, $t3)
+  8: $t0 := move($t2)
+  9: label L1
+ 10: $t5 := 1
+ 11: $t4 := ==($t0, $t5)
+ 12: if ($t4) goto 13 else goto 15
+ 13: label L5
+ 14: return ()
+ 15: label L6
+ 16: $t6 := 42
+ 17: abort($t6)
 }
diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/bug_13952_stack_balance_regression.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/bug_13952_stack_balance_regression.exp
index 76a0fb153d13f..e074d9d7a3f6b 100644
--- a/third_party/move/move-compiler-v2/tests/file-format-generator/bug_13952_stack_balance_regression.exp
+++ b/third_party/move/move-compiler-v2/tests/file-format-generator/bug_13952_stack_balance_regression.exp
@@ -26,10 +26,12 @@ B0:
 	4: TestVariant[0](Data/V1)
 	5: StLoc[1](loc1: bool)
 	6: CopyLoc[1](loc1: bool)
-	7: BrTrue(8)
+	7: BrFalse(9)
 B1:
-	8: MoveLoc[1](loc1: bool)
-	9: Ret
+	8: Branch(9)
+B2:
+	9: MoveLoc[1](loc1: bool)
+	10: Ret
 }
 test_v1v3(): bool /* def_idx: 1 */ {
 L0:	loc0: Data
@@ -48,40 +50,52 @@ B0:
 	6: TestVariant[0](Data/V1)
 	7: StLoc[2](loc2: bool)
 	8: CopyLoc[2](loc2: bool)
-	9: BrTrue(15)
+	9: BrFalse(13)
 B1:
 	10: MoveLoc[1](loc1: &Data)
-	11: TestVariant[1](Data/V3)
-	12: StLoc[2](loc2: bool)
-	13: CopyLoc[2](loc2: bool)
-	14: BrTrue(15)
+	11: Pop
+	12: Branch(19)
 B2:
-	15: PackVariant[1](Data/V3)
-	16: StLoc[3](loc3: Data)
-	17: MoveLoc[2](loc2: bool)
-	18: BrFalse(32)
+	13: MoveLoc[1](loc1: &Data)
+	14: TestVariant[1](Data/V3)
+	15: StLoc[2](loc2: bool)
+	16: CopyLoc[2](loc2: bool)
+	17: BrFalse(19)
 B3:
-	19: ImmBorrowLoc[3](loc3: Data)
-	20: StLoc[4](loc4: &Data)
-	21: CopyLoc[4](loc4: &Data)
-	22: TestVariant[0](Data/V1)
-	23: StLoc[5](loc5: bool)
-	24: CopyLoc[5](loc5: bool)
-	25: BrTrue(31)
+	18: Branch(19)
 B4:
-	26: MoveLoc[4](loc4: &Data)
-	27: TestVariant[1](Data/V3)
-	28: StLoc[5](loc5: bool)
-	29: CopyLoc[5](loc5: bool)
-	30: BrTrue(31)
+	19: PackVariant[1](Data/V3)
+	20: StLoc[3](loc3: Data)
+	21: MoveLoc[2](loc2: bool)
+	22: BrFalse(40)
 B5:
-	31: Branch(34)
+	23: ImmBorrowLoc[3](loc3: Data)
+	24: StLoc[4](loc4: &Data)
+	25: CopyLoc[4](loc4: &Data)
+	26: TestVariant[0](Data/V1)
+	27: StLoc[5](loc5: bool)
+	28: CopyLoc[5](loc5: bool)
+	29: BrFalse(33)
 B6:
-	32: LdFalse
-	33: StLoc[5](loc5: bool)
+	30: MoveLoc[4](loc4: &Data)
+	31: Pop
+	32: Branch(39)
 B7:
-	34: MoveLoc[5](loc5: bool)
-	35: Ret
+	33: MoveLoc[4](loc4: &Data)
+	34: TestVariant[1](Data/V3)
+	35: StLoc[5](loc5: bool)
+	36: CopyLoc[5](loc5: bool)
+	37: BrFalse(39)
+B8:
+	38: Branch(39)
+B9:
+	39: Branch(42)
+B10:
+	40: LdFalse
+	41: StLoc[5](loc5: bool)
+B11:
+	42: MoveLoc[5](loc5: bool)
+	43: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/bug_13952_stack_balance_regression.opt.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/bug_13952_stack_balance_regression.opt.exp
index 68d3c6b045aec..270b8bcd4d6c7 100644
--- a/third_party/move/move-compiler-v2/tests/file-format-generator/bug_13952_stack_balance_regression.opt.exp
+++ b/third_party/move/move-compiler-v2/tests/file-format-generator/bug_13952_stack_balance_regression.opt.exp
@@ -30,6 +30,8 @@ L0:	loc0: Data
 L1:	loc1: &Data
 L2:	loc2: bool
 L3:	loc3: Data
+L4:	loc4: &Data
+L5:	loc5: bool
 B0:
 	0: LdU64(43)
 	1: PackVariant[0](Data/V1)
@@ -40,35 +42,43 @@ B0:
 	6: TestVariant[0](Data/V1)
 	7: StLoc[2](loc2: bool)
 	8: CopyLoc[2](loc2: bool)
-	9: BrTrue(13)
+	9: BrFalse(34)
 B1:
 	10: MoveLoc[1](loc1: &Data)
-	11: TestVariant[1](Data/V3)
-	12: StLoc[2](loc2: bool)
+	11: Pop
 B2:
-	13: PackVariant[1](Data/V3)
-	14: StLoc[3](loc3: Data)
-	15: MoveLoc[2](loc2: bool)
-	16: BrFalse(29)
+	12: PackVariant[1](Data/V3)
+	13: StLoc[3](loc3: Data)
+	14: MoveLoc[2](loc2: bool)
+	15: BrFalse(31)
 B3:
-	17: ImmBorrowLoc[3](loc3: Data)
-	18: StLoc[1](loc1: &Data)
-	19: CopyLoc[1](loc1: &Data)
-	20: TestVariant[0](Data/V1)
-	21: StLoc[2](loc2: bool)
-	22: CopyLoc[2](loc2: bool)
-	23: BrTrue(27)
+	16: ImmBorrowLoc[3](loc3: Data)
+	17: StLoc[4](loc4: &Data)
+	18: CopyLoc[4](loc4: &Data)
+	19: TestVariant[0](Data/V1)
+	20: StLoc[5](loc5: bool)
+	21: CopyLoc[5](loc5: bool)
+	22: BrFalse(27)
 B4:
-	24: MoveLoc[1](loc1: &Data)
-	25: TestVariant[1](Data/V3)
-	26: StLoc[2](loc2: bool)
+	23: MoveLoc[4](loc4: &Data)
+	24: Pop
 B5:
-	27: MoveLoc[2](loc2: bool)
-	28: Ret
+	25: MoveLoc[5](loc5: bool)
+	26: Ret
 B6:
-	29: LdFalse
-	30: StLoc[2](loc2: bool)
-	31: Branch(27)
+	27: MoveLoc[4](loc4: &Data)
+	28: TestVariant[1](Data/V3)
+	29: StLoc[5](loc5: bool)
+	30: Branch(25)
+B7:
+	31: LdFalse
+	32: StLoc[5](loc5: bool)
+	33: Branch(25)
+B8:
+	34: MoveLoc[1](loc1: &Data)
+	35: TestVariant[1](Data/V3)
+	36: StLoc[2](loc2: bool)
+	37: Branch(12)
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/bug_14762.opt.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/bug_14762.opt.exp
index cce956293c50f..cf9cf708cd9e3 100644
--- a/third_party/move/move-compiler-v2/tests/file-format-generator/bug_14762.opt.exp
+++ b/third_party/move/move-compiler-v2/tests/file-format-generator/bug_14762.opt.exp
@@ -44,57 +44,59 @@ B1:
 	12: CopyLoc[5](loc3: u64)
 	13: CopyLoc[6](loc4: u64)
 	14: Lt
-	15: BrFalse(28)
+	15: BrTrue(17)
 B2:
-	16: CopyLoc[2](loc0: &vector<T>)
-	17: CopyLoc[5](loc3: u64)
-	18: VecImmBorrow(2)
-	19: ImmBorrowField[1](T.issuer: vector<u8>)
-	20: ReadRef
-	21: CopyLoc[1](Arg1: vector<u8>)
-	22: Eq
-	23: BrFalse(52)
+	16: Branch(29)
 B3:
-	24: LdTrue
-	25: StLoc[3](loc1: bool)
-	26: MoveLoc[5](loc3: u64)
-	27: StLoc[4](loc2: u64)
+	17: CopyLoc[2](loc0: &vector<T>)
+	18: CopyLoc[5](loc3: u64)
+	19: VecImmBorrow(2)
+	20: ImmBorrowField[1](T.issuer: vector<u8>)
+	21: ReadRef
+	22: CopyLoc[1](Arg1: vector<u8>)
+	23: Eq
+	24: BrFalse(53)
 B4:
-	28: Nop
-	29: MoveLoc[2](loc0: &vector<T>)
-	30: Pop
-	31: MoveLoc[3](loc1: bool)
-	32: StLoc[7](loc5: bool)
-	33: MoveLoc[4](loc2: u64)
-	34: StLoc[8](loc6: u64)
-	35: MoveLoc[7](loc5: bool)
-	36: BrFalse(47)
+	25: LdTrue
+	26: StLoc[3](loc1: bool)
+	27: MoveLoc[5](loc3: u64)
+	28: StLoc[4](loc2: u64)
 B5:
-	37: MoveLoc[0](Arg0: &mut S)
-	38: MutBorrowField[0](S.entries: vector<T>)
-	39: MoveLoc[8](loc6: u64)
-	40: Call vector::remove<T>(&mut vector<T>, u64): T
-	41: Call option::some<T>(T): Option<T>
-	42: StLoc[9](loc7: Option<T>)
+	29: Nop
+	30: MoveLoc[2](loc0: &vector<T>)
+	31: Pop
+	32: MoveLoc[3](loc1: bool)
+	33: StLoc[7](loc5: bool)
+	34: MoveLoc[4](loc2: u64)
+	35: StLoc[8](loc6: u64)
+	36: MoveLoc[7](loc5: bool)
+	37: BrFalse(48)
 B6:
-	43: MoveLoc[9](loc7: Option<T>)
-	44: StLoc[10](loc8: Option<T>)
-	45: MoveLoc[10](loc8: Option<T>)
-	46: Ret
+	38: MoveLoc[0](Arg0: &mut S)
+	39: MutBorrowField[0](S.entries: vector<T>)
+	40: MoveLoc[8](loc6: u64)
+	41: Call vector::remove<T>(&mut vector<T>, u64): T
+	42: Call option::some<T>(T): Option<T>
+	43: StLoc[9](loc7: Option<T>)
 B7:
-	47: MoveLoc[0](Arg0: &mut S)
-	48: Pop
-	49: Call option::none<T>(): Option<T>
-	50: StLoc[9](loc7: Option<T>)
-	51: Branch(43)
+	44: MoveLoc[9](loc7: Option<T>)
+	45: StLoc[10](loc8: Option<T>)
+	46: MoveLoc[10](loc8: Option<T>)
+	47: Ret
 B8:
-	52: LdU64(1)
-	53: StLoc[8](loc6: u64)
-	54: MoveLoc[5](loc3: u64)
-	55: MoveLoc[8](loc6: u64)
-	56: Add
-	57: StLoc[5](loc3: u64)
-	58: Branch(12)
+	48: MoveLoc[0](Arg0: &mut S)
+	49: Pop
+	50: Call option::none<T>(): Option<T>
+	51: StLoc[9](loc7: Option<T>)
+	52: Branch(44)
+B9:
+	53: LdU64(1)
+	54: StLoc[8](loc6: u64)
+	55: MoveLoc[5](loc3: u64)
+	56: MoveLoc[8](loc6: u64)
+	57: Add
+	58: StLoc[5](loc3: u64)
+	59: Branch(12)
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/loop.opt.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/loop.opt.exp
index 5d64b8f49eb84..c06febb790553 100644
--- a/third_party/move/move-compiler-v2/tests/file-format-generator/loop.opt.exp
+++ b/third_party/move/move-compiler-v2/tests/file-format-generator/loop.opt.exp
@@ -10,26 +10,28 @@ B0:
 	0: CopyLoc[0](Arg0: u64)
 	1: LdU64(0)
 	2: Gt
-	3: BrFalse(17)
+	3: BrFalse(18)
 B1:
 	4: CopyLoc[0](Arg0: u64)
 	5: LdU64(10)
 	6: Gt
-	7: BrFalse(12)
+	7: BrTrue(9)
 B2:
-	8: MoveLoc[0](Arg0: u64)
-	9: LdU64(1)
-	10: Sub
-	11: StLoc[0](Arg0: u64)
+	8: Branch(13)
 B3:
-	12: MoveLoc[0](Arg0: u64)
-	13: LdU64(1)
-	14: Sub
-	15: StLoc[0](Arg0: u64)
-	16: Branch(0)
+	9: MoveLoc[0](Arg0: u64)
+	10: LdU64(1)
+	11: Sub
+	12: StLoc[0](Arg0: u64)
 B4:
-	17: MoveLoc[0](Arg0: u64)
-	18: Ret
+	13: MoveLoc[0](Arg0: u64)
+	14: LdU64(1)
+	15: Sub
+	16: StLoc[0](Arg0: u64)
+	17: Branch(0)
+B5:
+	18: MoveLoc[0](Arg0: u64)
+	19: Ret
 }
 while_loop(Arg0: u64): u64 /* def_idx: 1 */ {
 L1:	loc0: u64
@@ -54,26 +56,32 @@ B0:
 	0: CopyLoc[0](Arg0: u64)
 	1: LdU64(0)
 	2: Gt
-	3: BrFalse(8)
+	3: BrTrue(5)
 B1:
-	4: CopyLoc[0](Arg0: u64)
-	5: LdU64(42)
-	6: Eq
-	7: BrFalse(10)
+	4: Branch(10)
 B2:
-	8: MoveLoc[0](Arg0: u64)
-	9: Ret
+	5: CopyLoc[0](Arg0: u64)
+	6: LdU64(42)
+	7: Eq
+	8: BrFalse(12)
 B3:
-	10: CopyLoc[0](Arg0: u64)
-	11: LdU64(21)
-	12: Eq
-	13: BrTrue(0)
+	9: Branch(10)
 B4:
-	14: MoveLoc[0](Arg0: u64)
-	15: LdU64(1)
-	16: Sub
-	17: StLoc[0](Arg0: u64)
-	18: Branch(0)
+	10: MoveLoc[0](Arg0: u64)
+	11: Ret
+B5:
+	12: CopyLoc[0](Arg0: u64)
+	13: LdU64(21)
+	14: Eq
+	15: BrFalse(17)
+B6:
+	16: Branch(0)
+B7:
+	17: MoveLoc[0](Arg0: u64)
+	18: LdU64(1)
+	19: Sub
+	20: StLoc[0](Arg0: u64)
+	21: Branch(0)
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.exp
index a6fcc25e9876a..84c3ab844270c 100644
--- a/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.exp
+++ b/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.exp
@@ -187,41 +187,51 @@ B1:
 	4: Pop
 	5: LdFalse
 	6: StLoc[1](loc0: bool)
-	7: Branch(32)
+	7: Branch(38)
 B2:
 	8: CopyLoc[0](Arg0: &Option<Option<u64>>)
 	9: TestVariantGeneric[3](Option/Some<Option<u64>>)
-	10: BrFalse(20)
+	10: BrTrue(12)
 B3:
-	11: CopyLoc[0](Arg0: &Option<Option<u64>>)
-	12: ImmBorrowVariantFieldGeneric[0](Some.value: Ty0)
-	13: TestVariantGeneric[4](Option/None<u64>)
-	14: BrFalse(20)
+	11: Branch(22)
 B4:
-	15: MoveLoc[0](Arg0: &Option<Option<u64>>)
-	16: Pop
-	17: LdFalse
-	18: StLoc[1](loc0: bool)
-	19: Branch(32)
+	12: CopyLoc[0](Arg0: &Option<Option<u64>>)
+	13: ImmBorrowVariantFieldGeneric[0](Some.value: Ty0)
+	14: TestVariantGeneric[4](Option/None<u64>)
+	15: BrTrue(17)
 B5:
-	20: CopyLoc[0](Arg0: &Option<Option<u64>>)
-	21: TestVariantGeneric[3](Option/Some<Option<u64>>)
-	22: BrFalse(30)
+	16: Branch(22)
 B6:
-	23: MoveLoc[0](Arg0: &Option<Option<u64>>)
-	24: ImmBorrowVariantFieldGeneric[0](Some.value: Ty0)
-	25: TestVariantGeneric[5](Option/Some<u64>)
-	26: BrFalse(30)
+	17: MoveLoc[0](Arg0: &Option<Option<u64>>)
+	18: Pop
+	19: LdFalse
+	20: StLoc[1](loc0: bool)
+	21: Branch(38)
 B7:
-	27: LdTrue
-	28: StLoc[1](loc0: bool)
-	29: Branch(32)
+	22: CopyLoc[0](Arg0: &Option<Option<u64>>)
+	23: TestVariantGeneric[3](Option/Some<Option<u64>>)
+	24: BrTrue(28)
 B8:
-	30: LdU64(14566554180833181697)
-	31: Abort
+	25: MoveLoc[0](Arg0: &Option<Option<u64>>)
+	26: Pop
+	27: Branch(36)
 B9:
-	32: MoveLoc[1](loc0: bool)
-	33: Ret
+	28: MoveLoc[0](Arg0: &Option<Option<u64>>)
+	29: ImmBorrowVariantFieldGeneric[0](Some.value: Ty0)
+	30: TestVariantGeneric[5](Option/Some<u64>)
+	31: BrTrue(33)
+B10:
+	32: Branch(36)
+B11:
+	33: LdTrue
+	34: StLoc[1](loc0: bool)
+	35: Branch(38)
+B12:
+	36: LdU64(14566554180833181697)
+	37: Abort
+B13:
+	38: MoveLoc[1](loc0: bool)
+	39: Ret
 }
 public outer_value(Arg0: Outer): u64 /* def_idx: 5 */ {
 L1:	loc0: &Outer
@@ -292,57 +302,61 @@ B1:
 	8: UnpackVariant[4](Outer/None)
 	9: LdU64(0)
 	10: StLoc[2](loc1: u64)
-	11: Branch(51)
+	11: Branch(53)
 B2:
 	12: CopyLoc[1](loc0: &Outer)
 	13: TestVariant[5](Outer/One)
-	14: BrFalse(26)
+	14: BrTrue(16)
 B3:
-	15: CopyLoc[1](loc0: &Outer)
-	16: ImmBorrowVariantField[1](One.i: Inner)
-	17: TestVariant[0](Inner/Inner1)
-	18: BrFalse(26)
+	15: Branch(28)
 B4:
-	19: MoveLoc[1](loc0: &Outer)
-	20: Pop
-	21: MoveLoc[0](Arg0: Outer)
-	22: UnpackVariant[5](Outer/One)
-	23: UnpackVariant[0](Inner/Inner1)
-	24: StLoc[2](loc1: u64)
-	25: Branch(51)
+	16: CopyLoc[1](loc0: &Outer)
+	17: ImmBorrowVariantField[1](One.i: Inner)
+	18: TestVariant[0](Inner/Inner1)
+	19: BrTrue(21)
 B5:
-	26: CopyLoc[1](loc0: &Outer)
-	27: TestVariant[5](Outer/One)
-	28: BrFalse(36)
+	20: Branch(28)
 B6:
-	29: MoveLoc[1](loc0: &Outer)
-	30: Pop
-	31: MoveLoc[0](Arg0: Outer)
-	32: UnpackVariant[5](Outer/One)
-	33: Call inner_value(Inner): u64
-	34: StLoc[2](loc1: u64)
-	35: Branch(51)
+	21: MoveLoc[1](loc0: &Outer)
+	22: Pop
+	23: MoveLoc[0](Arg0: Outer)
+	24: UnpackVariant[5](Outer/One)
+	25: UnpackVariant[0](Inner/Inner1)
+	26: StLoc[2](loc1: u64)
+	27: Branch(53)
 B7:
-	36: MoveLoc[1](loc0: &Outer)
-	37: TestVariant[6](Outer/Two)
-	38: BrFalse(49)
+	28: CopyLoc[1](loc0: &Outer)
+	29: TestVariant[5](Outer/One)
+	30: BrFalse(38)
 B8:
-	39: MoveLoc[0](Arg0: Outer)
-	40: UnpackVariant[6](Outer/Two)
-	41: StLoc[3](loc2: Box)
-	42: Call inner_value(Inner): u64
-	43: ImmBorrowLoc[3](loc2: Box)
-	44: ImmBorrowField[0](Box.x: u64)
-	45: ReadRef
-	46: Add
-	47: StLoc[2](loc1: u64)
-	48: Branch(51)
+	31: MoveLoc[1](loc0: &Outer)
+	32: Pop
+	33: MoveLoc[0](Arg0: Outer)
+	34: UnpackVariant[5](Outer/One)
+	35: Call inner_value(Inner): u64
+	36: StLoc[2](loc1: u64)
+	37: Branch(53)
 B9:
-	49: LdU64(14566554180833181697)
-	50: Abort
+	38: MoveLoc[1](loc0: &Outer)
+	39: TestVariant[6](Outer/Two)
+	40: BrFalse(51)
 B10:
-	51: MoveLoc[2](loc1: u64)
-	52: Ret
+	41: MoveLoc[0](Arg0: Outer)
+	42: UnpackVariant[6](Outer/Two)
+	43: StLoc[3](loc2: Box)
+	44: Call inner_value(Inner): u64
+	45: ImmBorrowLoc[3](loc2: Box)
+	46: ImmBorrowField[0](Box.x: u64)
+	47: ReadRef
+	48: Add
+	49: StLoc[2](loc1: u64)
+	50: Branch(53)
+B11:
+	51: LdU64(14566554180833181697)
+	52: Abort
+B12:
+	53: MoveLoc[2](loc1: u64)
+	54: Ret
 }
 public outer_value_with_cond(Arg0: Outer): u64 /* def_idx: 7 */ {
 L1:	loc0: &Outer
@@ -362,61 +376,65 @@ B1:
 	8: UnpackVariant[4](Outer/None)
 	9: LdU64(0)
 	10: StLoc[2](loc1: u64)
-	11: Branch(55)
+	11: Branch(57)
 B2:
 	12: CopyLoc[1](loc0: &Outer)
 	13: TestVariant[5](Outer/One)
-	14: BrFalse(30)
+	14: BrTrue(16)
 B3:
-	15: CopyLoc[1](loc0: &Outer)
-	16: ImmBorrowVariantField[1](One.i: Inner)
-	17: StLoc[3](loc2: &Inner)
-	18: MoveLoc[3](loc2: &Inner)
-	19: Call is_inner1(&Inner): bool
-	20: BrFalse(30)
+	15: Branch(32)
 B4:
-	21: MoveLoc[1](loc0: &Outer)
-	22: Pop
-	23: MoveLoc[0](Arg0: Outer)
-	24: UnpackVariant[5](Outer/One)
-	25: Call inner_value(Inner): u64
-	26: LdU64(2)
-	27: Mod
-	28: StLoc[2](loc1: u64)
-	29: Branch(55)
+	16: CopyLoc[1](loc0: &Outer)
+	17: ImmBorrowVariantField[1](One.i: Inner)
+	18: StLoc[3](loc2: &Inner)
+	19: MoveLoc[3](loc2: &Inner)
+	20: Call is_inner1(&Inner): bool
+	21: BrTrue(23)
 B5:
-	30: CopyLoc[1](loc0: &Outer)
-	31: TestVariant[5](Outer/One)
-	32: BrFalse(40)
+	22: Branch(32)
 B6:
-	33: MoveLoc[1](loc0: &Outer)
-	34: Pop
-	35: MoveLoc[0](Arg0: Outer)
-	36: UnpackVariant[5](Outer/One)
-	37: Call inner_value(Inner): u64
-	38: StLoc[2](loc1: u64)
-	39: Branch(55)
+	23: MoveLoc[1](loc0: &Outer)
+	24: Pop
+	25: MoveLoc[0](Arg0: Outer)
+	26: UnpackVariant[5](Outer/One)
+	27: Call inner_value(Inner): u64
+	28: LdU64(2)
+	29: Mod
+	30: StLoc[2](loc1: u64)
+	31: Branch(57)
 B7:
-	40: MoveLoc[1](loc0: &Outer)
-	41: TestVariant[6](Outer/Two)
-	42: BrFalse(53)
+	32: CopyLoc[1](loc0: &Outer)
+	33: TestVariant[5](Outer/One)
+	34: BrFalse(42)
 B8:
-	43: MoveLoc[0](Arg0: Outer)
-	44: UnpackVariant[6](Outer/Two)
-	45: StLoc[4](loc3: Box)
-	46: Call inner_value(Inner): u64
-	47: ImmBorrowLoc[4](loc3: Box)
-	48: ImmBorrowField[0](Box.x: u64)
-	49: ReadRef
-	50: Add
-	51: StLoc[2](loc1: u64)
-	52: Branch(55)
+	35: MoveLoc[1](loc0: &Outer)
+	36: Pop
+	37: MoveLoc[0](Arg0: Outer)
+	38: UnpackVariant[5](Outer/One)
+	39: Call inner_value(Inner): u64
+	40: StLoc[2](loc1: u64)
+	41: Branch(57)
 B9:
-	53: LdU64(14566554180833181697)
-	54: Abort
+	42: MoveLoc[1](loc0: &Outer)
+	43: TestVariant[6](Outer/Two)
+	44: BrFalse(55)
 B10:
-	55: MoveLoc[2](loc1: u64)
-	56: Ret
+	45: MoveLoc[0](Arg0: Outer)
+	46: UnpackVariant[6](Outer/Two)
+	47: StLoc[4](loc3: Box)
+	48: Call inner_value(Inner): u64
+	49: ImmBorrowLoc[4](loc3: Box)
+	50: ImmBorrowField[0](Box.x: u64)
+	51: ReadRef
+	52: Add
+	53: StLoc[2](loc1: u64)
+	54: Branch(57)
+B11:
+	55: LdU64(14566554180833181697)
+	56: Abort
+B12:
+	57: MoveLoc[2](loc1: u64)
+	58: Ret
 }
 public outer_value_with_cond_ref(Arg0: &Outer): bool /* def_idx: 8 */ {
 L1:	loc0: bool
@@ -429,50 +447,54 @@ B1:
 	4: Pop
 	5: LdFalse
 	6: StLoc[1](loc0: bool)
-	7: Branch(40)
+	7: Branch(42)
 B2:
 	8: CopyLoc[0](Arg0: &Outer)
 	9: TestVariant[5](Outer/One)
-	10: BrFalse(20)
+	10: BrTrue(12)
 B3:
-	11: CopyLoc[0](Arg0: &Outer)
-	12: ImmBorrowVariantField[1](One.i: Inner)
-	13: Call is_inner1(&Inner): bool
-	14: BrFalse(20)
+	11: Branch(22)
 B4:
-	15: MoveLoc[0](Arg0: &Outer)
-	16: Pop
-	17: LdTrue
-	18: StLoc[1](loc0: bool)
-	19: Branch(40)
+	12: CopyLoc[0](Arg0: &Outer)
+	13: ImmBorrowVariantField[1](One.i: Inner)
+	14: Call is_inner1(&Inner): bool
+	15: BrTrue(17)
 B5:
-	20: CopyLoc[0](Arg0: &Outer)
-	21: TestVariant[5](Outer/One)
-	22: BrFalse(28)
+	16: Branch(22)
 B6:
-	23: MoveLoc[0](Arg0: &Outer)
-	24: ImmBorrowVariantField[1](One.i: Inner)
-	25: Call is_inner1(&Inner): bool
-	26: StLoc[1](loc0: bool)
-	27: Branch(40)
+	17: MoveLoc[0](Arg0: &Outer)
+	18: Pop
+	19: LdTrue
+	20: StLoc[1](loc0: bool)
+	21: Branch(42)
 B7:
-	28: CopyLoc[0](Arg0: &Outer)
-	29: TestVariant[6](Outer/Two)
-	30: BrFalse(36)
+	22: CopyLoc[0](Arg0: &Outer)
+	23: TestVariant[5](Outer/One)
+	24: BrFalse(30)
 B8:
-	31: MoveLoc[0](Arg0: &Outer)
-	32: ImmBorrowVariantField[2](Two.i: Inner)
-	33: Call is_inner1(&Inner): bool
-	34: StLoc[1](loc0: bool)
-	35: Branch(40)
+	25: MoveLoc[0](Arg0: &Outer)
+	26: ImmBorrowVariantField[1](One.i: Inner)
+	27: Call is_inner1(&Inner): bool
+	28: StLoc[1](loc0: bool)
+	29: Branch(42)
 B9:
-	36: MoveLoc[0](Arg0: &Outer)
-	37: Pop
-	38: LdU64(14566554180833181697)
-	39: Abort
+	30: CopyLoc[0](Arg0: &Outer)
+	31: TestVariant[6](Outer/Two)
+	32: BrFalse(38)
 B10:
-	40: MoveLoc[1](loc0: bool)
-	41: Ret
+	33: MoveLoc[0](Arg0: &Outer)
+	34: ImmBorrowVariantField[2](Two.i: Inner)
+	35: Call is_inner1(&Inner): bool
+	36: StLoc[1](loc0: bool)
+	37: Branch(42)
+B11:
+	38: MoveLoc[0](Arg0: &Outer)
+	39: Pop
+	40: LdU64(14566554180833181697)
+	41: Abort
+B12:
+	42: MoveLoc[1](loc0: bool)
+	43: Ret
 }
 select_common_fields(Arg0: CommonFields): u64 /* def_idx: 9 */ {
 L1:	loc0: &CommonFields
@@ -526,26 +548,30 @@ B0:
 	1: StLoc[1](loc0: &CommonFieldsAtDifferentOffset)
 	2: CopyLoc[1](loc0: &CommonFieldsAtDifferentOffset)
 	3: TestVariant[9](CommonFieldsAtDifferentOffset/Bar)
-	4: BrTrue(9)
+	4: BrFalse(6)
 B1:
-	5: CopyLoc[1](loc0: &CommonFieldsAtDifferentOffset)
-	6: TestVariant[10](CommonFieldsAtDifferentOffset/Balt)
-	7: BrTrue(9)
+	5: Branch(11)
 B2:
-	8: Branch(13)
+	6: CopyLoc[1](loc0: &CommonFieldsAtDifferentOffset)
+	7: TestVariant[10](CommonFieldsAtDifferentOffset/Balt)
+	8: BrFalse(10)
 B3:
-	9: MoveLoc[1](loc0: &CommonFieldsAtDifferentOffset)
-	10: ImmBorrowVariantField[4](Bar.z|Balt.z: u64)
-	11: StLoc[2](loc1: &u64)
-	12: Branch(16)
+	9: Branch(11)
 B4:
-	13: MoveLoc[1](loc0: &CommonFieldsAtDifferentOffset)
-	14: ImmBorrowVariantField[5](Baz.z: u64)
-	15: StLoc[2](loc1: &u64)
+	10: Branch(15)
 B5:
-	16: MoveLoc[2](loc1: &u64)
-	17: ReadRef
-	18: Ret
+	11: MoveLoc[1](loc0: &CommonFieldsAtDifferentOffset)
+	12: ImmBorrowVariantField[4](Bar.z|Balt.z: u64)
+	13: StLoc[2](loc1: &u64)
+	14: Branch(18)
+B6:
+	15: MoveLoc[1](loc0: &CommonFieldsAtDifferentOffset)
+	16: ImmBorrowVariantField[5](Baz.z: u64)
+	17: StLoc[2](loc1: &u64)
+B7:
+	18: MoveLoc[2](loc1: &u64)
+	19: ReadRef
+	20: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp b/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp
index 46913b5e0a72b..34f5133865c63 100644
--- a/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp
+++ b/third_party/move/move-compiler-v2/tests/file-format-generator/struct_variants.opt.exp
@@ -177,34 +177,43 @@ B2:
 B3:
 	9: CopyLoc[0](Arg0: &Option<Option<u64>>)
 	10: TestVariantGeneric[3](Option/Some<Option<u64>>)
-	11: BrFalse(21)
+	11: BrTrue(28)
 B4:
-	12: CopyLoc[0](Arg0: &Option<Option<u64>>)
-	13: ImmBorrowVariantFieldGeneric[0](Some.value: Ty0)
-	14: TestVariantGeneric[4](Option/None<u64>)
-	15: BrFalse(21)
+	12: Branch(13)
 B5:
+	13: CopyLoc[0](Arg0: &Option<Option<u64>>)
+	14: TestVariantGeneric[3](Option/Some<Option<u64>>)
+	15: BrTrue(20)
+B6:
 	16: MoveLoc[0](Arg0: &Option<Option<u64>>)
 	17: Pop
-	18: LdFalse
-	19: StLoc[1](loc0: bool)
-	20: Branch(7)
-B6:
-	21: CopyLoc[0](Arg0: &Option<Option<u64>>)
-	22: TestVariantGeneric[3](Option/Some<Option<u64>>)
-	23: BrFalse(31)
 B7:
-	24: MoveLoc[0](Arg0: &Option<Option<u64>>)
-	25: ImmBorrowVariantFieldGeneric[0](Some.value: Ty0)
-	26: TestVariantGeneric[5](Option/Some<u64>)
-	27: BrFalse(31)
+	18: LdU64(14566554180833181697)
+	19: Abort
 B8:
-	28: LdTrue
-	29: StLoc[1](loc0: bool)
-	30: Branch(7)
+	20: MoveLoc[0](Arg0: &Option<Option<u64>>)
+	21: ImmBorrowVariantFieldGeneric[0](Some.value: Ty0)
+	22: TestVariantGeneric[4](Option/Some<u64>)
+	23: BrTrue(25)
 B9:
-	31: LdU64(14566554180833181697)
-	32: Abort
+	24: Branch(18)
+B10:
+	25: LdTrue
+	26: StLoc[1](loc0: bool)
+	27: Branch(7)
+B11:
+	28: CopyLoc[0](Arg0: &Option<Option<u64>>)
+	29: ImmBorrowVariantFieldGeneric[0](Some.value: Ty0)
+	30: TestVariantGeneric[5](Option/None<u64>)
+	31: BrTrue(33)
+B12:
+	32: Branch(13)
+B13:
+	33: MoveLoc[0](Arg0: &Option<Option<u64>>)
+	34: Pop
+	35: LdFalse
+	36: StLoc[1](loc0: bool)
+	37: Branch(7)
 }
 public outer_value(Arg0: Outer): u64 /* def_idx: 5 */ {
 L1:	loc0: &Outer
@@ -280,50 +289,54 @@ B2:
 B3:
 	13: CopyLoc[1](loc0: &Outer)
 	14: TestVariant[5](Outer/One)
-	15: BrFalse(27)
+	15: BrTrue(42)
 B4:
-	16: CopyLoc[1](loc0: &Outer)
-	17: ImmBorrowVariantField[1](One.i: Inner)
-	18: TestVariant[0](Inner/Inner1)
-	19: BrFalse(27)
+	16: Branch(17)
 B5:
+	17: CopyLoc[1](loc0: &Outer)
+	18: TestVariant[5](Outer/One)
+	19: BrFalse(27)
+B6:
 	20: MoveLoc[1](loc0: &Outer)
 	21: Pop
 	22: MoveLoc[0](Arg0: Outer)
 	23: UnpackVariant[5](Outer/One)
-	24: UnpackVariant[0](Inner/Inner1)
+	24: Call inner_value(Inner): u64
 	25: StLoc[2](loc1: u64)
 	26: Branch(11)
-B6:
-	27: CopyLoc[1](loc0: &Outer)
-	28: TestVariant[5](Outer/One)
-	29: BrFalse(37)
 B7:
-	30: MoveLoc[1](loc0: &Outer)
-	31: Pop
-	32: MoveLoc[0](Arg0: Outer)
-	33: UnpackVariant[5](Outer/One)
-	34: Call inner_value(Inner): u64
-	35: StLoc[2](loc1: u64)
-	36: Branch(11)
+	27: MoveLoc[1](loc0: &Outer)
+	28: TestVariant[6](Outer/Two)
+	29: BrFalse(40)
 B8:
-	37: MoveLoc[1](loc0: &Outer)
-	38: TestVariant[6](Outer/Two)
-	39: BrFalse(50)
+	30: MoveLoc[0](Arg0: Outer)
+	31: UnpackVariant[6](Outer/Two)
+	32: StLoc[3](loc2: Box)
+	33: Call inner_value(Inner): u64
+	34: ImmBorrowLoc[3](loc2: Box)
+	35: ImmBorrowField[0](Box.x: u64)
+	36: ReadRef
+	37: Add
+	38: StLoc[2](loc1: u64)
+	39: Branch(11)
 B9:
-	40: MoveLoc[0](Arg0: Outer)
-	41: UnpackVariant[6](Outer/Two)
-	42: StLoc[3](loc2: Box)
-	43: Call inner_value(Inner): u64
-	44: ImmBorrowLoc[3](loc2: Box)
-	45: ImmBorrowField[0](Box.x: u64)
-	46: ReadRef
-	47: Add
-	48: StLoc[2](loc1: u64)
-	49: Branch(11)
+	40: LdU64(14566554180833181697)
+	41: Abort
 B10:
-	50: LdU64(14566554180833181697)
-	51: Abort
+	42: CopyLoc[1](loc0: &Outer)
+	43: ImmBorrowVariantField[1](One.i: Inner)
+	44: TestVariant[0](Inner/Inner1)
+	45: BrTrue(47)
+B11:
+	46: Branch(17)
+B12:
+	47: MoveLoc[1](loc0: &Outer)
+	48: Pop
+	49: MoveLoc[0](Arg0: Outer)
+	50: UnpackVariant[5](Outer/One)
+	51: UnpackVariant[0](Inner/Inner1)
+	52: StLoc[2](loc1: u64)
+	53: Branch(11)
 }
 public outer_value_with_cond(Arg0: Outer): u64 /* def_idx: 7 */ {
 L1:	loc0: &Outer
@@ -348,52 +361,56 @@ B2:
 B3:
 	13: CopyLoc[1](loc0: &Outer)
 	14: TestVariant[5](Outer/One)
-	15: BrFalse(29)
+	15: BrTrue(42)
 B4:
-	16: CopyLoc[1](loc0: &Outer)
-	17: ImmBorrowVariantField[1](One.i: Inner)
-	18: Call is_inner1(&Inner): bool
-	19: BrFalse(29)
+	16: Branch(17)
 B5:
+	17: CopyLoc[1](loc0: &Outer)
+	18: TestVariant[5](Outer/One)
+	19: BrFalse(27)
+B6:
 	20: MoveLoc[1](loc0: &Outer)
 	21: Pop
 	22: MoveLoc[0](Arg0: Outer)
 	23: UnpackVariant[5](Outer/One)
 	24: Call inner_value(Inner): u64
-	25: LdU64(2)
-	26: Mod
-	27: StLoc[2](loc1: u64)
-	28: Branch(11)
-B6:
-	29: CopyLoc[1](loc0: &Outer)
-	30: TestVariant[5](Outer/One)
-	31: BrFalse(39)
+	25: StLoc[2](loc1: u64)
+	26: Branch(11)
 B7:
-	32: MoveLoc[1](loc0: &Outer)
-	33: Pop
-	34: MoveLoc[0](Arg0: Outer)
-	35: UnpackVariant[5](Outer/One)
-	36: Call inner_value(Inner): u64
-	37: StLoc[2](loc1: u64)
-	38: Branch(11)
+	27: MoveLoc[1](loc0: &Outer)
+	28: TestVariant[6](Outer/Two)
+	29: BrFalse(40)
 B8:
-	39: MoveLoc[1](loc0: &Outer)
-	40: TestVariant[6](Outer/Two)
-	41: BrFalse(52)
+	30: MoveLoc[0](Arg0: Outer)
+	31: UnpackVariant[6](Outer/Two)
+	32: StLoc[3](loc2: Box)
+	33: Call inner_value(Inner): u64
+	34: ImmBorrowLoc[3](loc2: Box)
+	35: ImmBorrowField[0](Box.x: u64)
+	36: ReadRef
+	37: Add
+	38: StLoc[2](loc1: u64)
+	39: Branch(11)
 B9:
-	42: MoveLoc[0](Arg0: Outer)
-	43: UnpackVariant[6](Outer/Two)
-	44: StLoc[3](loc2: Box)
-	45: Call inner_value(Inner): u64
-	46: ImmBorrowLoc[3](loc2: Box)
-	47: ImmBorrowField[0](Box.x: u64)
-	48: ReadRef
-	49: Add
-	50: StLoc[2](loc1: u64)
-	51: Branch(11)
+	40: LdU64(14566554180833181697)
+	41: Abort
 B10:
-	52: LdU64(14566554180833181697)
-	53: Abort
+	42: CopyLoc[1](loc0: &Outer)
+	43: ImmBorrowVariantField[1](One.i: Inner)
+	44: Call is_inner1(&Inner): bool
+	45: BrTrue(47)
+B11:
+	46: Branch(17)
+B12:
+	47: MoveLoc[1](loc0: &Outer)
+	48: Pop
+	49: MoveLoc[0](Arg0: Outer)
+	50: UnpackVariant[5](Outer/One)
+	51: Call inner_value(Inner): u64
+	52: LdU64(2)
+	53: Mod
+	54: StLoc[2](loc1: u64)
+	55: Branch(11)
 }
 public outer_value_with_cond_ref(Arg0: &Outer): bool /* def_idx: 8 */ {
 L1:	loc0: bool
@@ -412,43 +429,47 @@ B2:
 B3:
 	9: CopyLoc[0](Arg0: &Outer)
 	10: TestVariant[5](Outer/One)
-	11: BrFalse(21)
+	11: BrTrue(33)
 B4:
-	12: CopyLoc[0](Arg0: &Outer)
-	13: ImmBorrowVariantField[1](One.i: Inner)
-	14: Call is_inner1(&Inner): bool
-	15: BrFalse(21)
+	12: Branch(13)
 B5:
+	13: CopyLoc[0](Arg0: &Outer)
+	14: TestVariant[5](Outer/One)
+	15: BrFalse(21)
+B6:
 	16: MoveLoc[0](Arg0: &Outer)
-	17: Pop
-	18: LdTrue
+	17: ImmBorrowVariantField[1](One.i: Inner)
+	18: Call is_inner1(&Inner): bool
 	19: StLoc[1](loc0: bool)
 	20: Branch(7)
-B6:
+B7:
 	21: CopyLoc[0](Arg0: &Outer)
-	22: TestVariant[5](Outer/One)
+	22: TestVariant[6](Outer/Two)
 	23: BrFalse(29)
-B7:
+B8:
 	24: MoveLoc[0](Arg0: &Outer)
-	25: ImmBorrowVariantField[1](One.i: Inner)
+	25: ImmBorrowVariantField[2](Two.i: Inner)
 	26: Call is_inner1(&Inner): bool
 	27: StLoc[1](loc0: bool)
 	28: Branch(7)
-B8:
-	29: CopyLoc[0](Arg0: &Outer)
-	30: TestVariant[6](Outer/Two)
-	31: BrFalse(37)
 B9:
-	32: MoveLoc[0](Arg0: &Outer)
-	33: ImmBorrowVariantField[2](Two.i: Inner)
-	34: Call is_inner1(&Inner): bool
-	35: StLoc[1](loc0: bool)
-	36: Branch(7)
+	29: MoveLoc[0](Arg0: &Outer)
+	30: Pop
+	31: LdU64(14566554180833181697)
+	32: Abort
 B10:
-	37: MoveLoc[0](Arg0: &Outer)
-	38: Pop
-	39: LdU64(14566554180833181697)
-	40: Abort
+	33: CopyLoc[0](Arg0: &Outer)
+	34: ImmBorrowVariantField[1](One.i: Inner)
+	35: Call is_inner1(&Inner): bool
+	36: BrTrue(38)
+B11:
+	37: Branch(13)
+B12:
+	38: MoveLoc[0](Arg0: &Outer)
+	39: Pop
+	40: LdTrue
+	41: StLoc[1](loc0: bool)
+	42: Branch(7)
 }
 select_common_fields(Arg0: CommonFields): u64 /* def_idx: 9 */ {
 L1:	loc0: &CommonFields
@@ -498,24 +519,28 @@ B0:
 	1: StLoc[1](loc0: &CommonFieldsAtDifferentOffset)
 	2: CopyLoc[1](loc0: &CommonFieldsAtDifferentOffset)
 	3: TestVariant[9](CommonFieldsAtDifferentOffset/Bar)
-	4: BrTrue(14)
+	4: BrFalse(12)
 B1:
-	5: CopyLoc[1](loc0: &CommonFieldsAtDifferentOffset)
-	6: TestVariant[10](CommonFieldsAtDifferentOffset/Balt)
-	7: BrTrue(14)
+	5: Branch(6)
 B2:
-	8: MoveLoc[1](loc0: &CommonFieldsAtDifferentOffset)
-	9: ImmBorrowVariantField[4](Baz.z: u64)
-	10: StLoc[2](loc1: &u64)
+	6: MoveLoc[1](loc0: &CommonFieldsAtDifferentOffset)
+	7: ImmBorrowVariantField[4](Bar.z|Balt.z: u64)
+	8: StLoc[2](loc1: &u64)
 B3:
-	11: MoveLoc[2](loc1: &u64)
-	12: ReadRef
-	13: Ret
+	9: MoveLoc[2](loc1: &u64)
+	10: ReadRef
+	11: Ret
 B4:
-	14: MoveLoc[1](loc0: &CommonFieldsAtDifferentOffset)
-	15: ImmBorrowVariantField[5](Bar.z|Balt.z: u64)
-	16: StLoc[2](loc1: &u64)
-	17: Branch(11)
+	12: CopyLoc[1](loc0: &CommonFieldsAtDifferentOffset)
+	13: TestVariant[10](CommonFieldsAtDifferentOffset/Balt)
+	14: BrFalse(16)
+B5:
+	15: Branch(6)
+B6:
+	16: MoveLoc[1](loc0: &CommonFieldsAtDifferentOffset)
+	17: ImmBorrowVariantField[5](Baz.z: u64)
+	18: StLoc[2](loc1: &u64)
+	19: Branch(9)
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/loop_02.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/loop_02.off.exp
index 5767b998216b4..690a6f78c649f 100644
--- a/third_party/move/move-compiler-v2/tests/flush-writes/loop_02.off.exp
+++ b/third_party/move/move-compiler-v2/tests/flush-writes/loop_02.off.exp
@@ -25,9 +25,11 @@ B1:
 	5: CopyLoc[0](loc0: u64)
 	6: LdU64(10)
 	7: Gt
-	8: BrFalse(2)
+	8: BrTrue(10)
 B2:
-	9: Ret
+	9: Branch(2)
+B3:
+	10: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/loop_02.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/loop_02.on.exp
index 17d60960c3819..55dca74a4e2ef 100644
--- a/third_party/move/move-compiler-v2/tests/flush-writes/loop_02.on.exp
+++ b/third_party/move/move-compiler-v2/tests/flush-writes/loop_02.on.exp
@@ -33,11 +33,15 @@ public fun m::test() {
      # live vars: $t0, $t1
   5: $t2 := >($t0, $t1)
      # live vars: $t0, $t2
-  6: if ($t2) goto 7 else goto 1
+  6: if ($t2) goto 9 else goto 7
      # live vars: $t0
-  7: label L2
+  7: label L3
+     # live vars: $t0
+  8: goto 1
+     # live vars: $t0
+  9: label L2
      # live vars:
-  8: return ()
+ 10: return ()
 }
 
 
@@ -67,9 +71,11 @@ B1:
 	5: CopyLoc[0](loc0: u64)
 	6: LdU64(10)
 	7: Gt
-	8: BrFalse(2)
+	8: BrTrue(10)
 B2:
-	9: Ret
+	9: Branch(2)
+B3:
+	10: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.off.exp
index 80f5dfb218a9f..fc1ffb79f8430 100644
--- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.off.exp
+++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.off.exp
@@ -29,13 +29,15 @@ B0:
 	6: StLoc[3](loc3: bool)
 	7: StLoc[4](loc4: u64)
 	8: MoveLoc[3](loc3: bool)
-	9: BrFalse(11)
+	9: BrTrue(11)
 B1:
-	10: Call bar()
+	10: Branch(12)
 B2:
-	11: MoveLoc[4](loc4: u64)
-	12: MoveLoc[1](loc1: u64)
-	13: Ret
+	11: Call bar()
+B3:
+	12: MoveLoc[4](loc4: u64)
+	13: MoveLoc[1](loc1: u64)
+	14: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.on.exp
index 704f64ec8c641..cd5b039374e09 100644
--- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.on.exp
+++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_02.on.exp
@@ -39,15 +39,19 @@ public fun m::test(): (u64, u64) {
      # live vars: $t2, $t3, $t4, $t6
   4: $t5 := ==($t3, $t6)
      # live vars: $t2, $t4, $t5
-  5: if ($t5) goto 6 else goto 8
+  5: if ($t5) goto 8 else goto 6
      # live vars: $t2, $t4
-  6: label L0
+  6: label L3
      # live vars: $t2, $t4
-  7: m::bar()
+  7: goto 10
      # live vars: $t2, $t4
-  8: label L2
+  8: label L0
      # live vars: $t2, $t4
-  9: return ($t2, $t4)
+  9: m::bar()
+     # live vars: $t2, $t4
+ 10: label L2
+     # live vars: $t2, $t4
+ 11: return ($t2, $t4)
 }
 
 
@@ -76,13 +80,15 @@ B0:
 	4: StLoc[1](loc1: u64)
 	5: LdU64(0)
 	6: Eq
-	7: BrFalse(9)
+	7: BrTrue(9)
 B1:
-	8: Call bar()
+	8: Branch(10)
 B2:
-	9: MoveLoc[0](loc0: u64)
-	10: MoveLoc[1](loc1: u64)
-	11: Ret
+	9: Call bar()
+B3:
+	10: MoveLoc[0](loc0: u64)
+	11: MoveLoc[1](loc1: u64)
+	12: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.off.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.off.exp
index a4dfa90b2ba3c..cafdb9ffef84d 100644
--- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.off.exp
+++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.off.exp
@@ -26,25 +26,31 @@ B0:
 	2: StLoc[2](loc2: u64)
 	3: LdU64(0)
 	4: Eq
-	5: BrFalse(7)
+	5: BrTrue(7)
 B1:
-	6: Call bar()
+	6: Branch(8)
 B2:
-	7: MoveLoc[2](loc2: u64)
-	8: LdU64(0)
-	9: Eq
-	10: BrFalse(12)
+	7: Call bar()
 B3:
-	11: Call bar()
+	8: MoveLoc[2](loc2: u64)
+	9: LdU64(0)
+	10: Eq
+	11: BrTrue(13)
 B4:
-	12: MoveLoc[1](loc1: u64)
-	13: LdU64(0)
-	14: Eq
-	15: BrFalse(17)
+	12: Branch(14)
 B5:
-	16: Call bar()
+	13: Call bar()
 B6:
-	17: Ret
+	14: MoveLoc[1](loc1: u64)
+	15: LdU64(0)
+	16: Eq
+	17: BrTrue(19)
+B7:
+	18: Branch(20)
+B8:
+	19: Call bar()
+B9:
+	20: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.on.exp b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.on.exp
index 7378d5205263d..9af909489ad96 100644
--- a/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.on.exp
+++ b/third_party/move/move-compiler-v2/tests/flush-writes/unused_flush_early_03.on.exp
@@ -42,39 +42,51 @@ public fun m::test1() {
      # live vars: $t0, $t1, $t2, $t4
   2: $t3 := ==($t0, $t4)
      # live vars: $t1, $t2, $t3
-  3: if ($t3) goto 4 else goto 6
+  3: if ($t3) goto 6 else goto 4
      # live vars: $t1, $t2
-  4: label L0
+  4: label L9
      # live vars: $t1, $t2
-  5: m::bar()
+  5: goto 8
      # live vars: $t1, $t2
-  6: label L2
+  6: label L0
      # live vars: $t1, $t2
-  7: $t0 := 0
+  7: m::bar()
+     # live vars: $t1, $t2
+  8: label L2
+     # live vars: $t1, $t2
+  9: $t0 := 0
      # live vars: $t0, $t1, $t2
-  8: $t3 := ==($t1, $t0)
+ 10: $t3 := ==($t1, $t0)
      # live vars: $t2, $t3
-  9: if ($t3) goto 10 else goto 12
+ 11: if ($t3) goto 14 else goto 12
+     # live vars: $t2
+ 12: label L10
      # live vars: $t2
- 10: label L3
+ 13: goto 16
      # live vars: $t2
- 11: m::bar()
+ 14: label L3
      # live vars: $t2
- 12: label L5
+ 15: m::bar()
      # live vars: $t2
- 13: $t0 := 0
+ 16: label L5
+     # live vars: $t2
+ 17: $t0 := 0
      # live vars: $t0, $t2
- 14: $t3 := ==($t2, $t0)
+ 18: $t3 := ==($t2, $t0)
      # live vars: $t3
- 15: if ($t3) goto 16 else goto 18
+ 19: if ($t3) goto 22 else goto 20
+     # live vars:
+ 20: label L11
+     # live vars:
+ 21: goto 24
      # live vars:
- 16: label L6
+ 22: label L6
      # live vars:
- 17: m::bar()
+ 23: m::bar()
      # live vars:
- 18: label L8
+ 24: label L8
      # live vars:
- 19: return ()
+ 25: return ()
 }
 
 
@@ -104,25 +116,31 @@ B0:
 	2: StLoc[1](loc1: u64)
 	3: LdU64(0)
 	4: Eq
-	5: BrFalse(7)
+	5: BrTrue(7)
 B1:
-	6: Call bar()
+	6: Branch(8)
 B2:
-	7: MoveLoc[1](loc1: u64)
-	8: LdU64(0)
-	9: Eq
-	10: BrFalse(12)
+	7: Call bar()
 B3:
-	11: Call bar()
+	8: MoveLoc[1](loc1: u64)
+	9: LdU64(0)
+	10: Eq
+	11: BrTrue(13)
 B4:
-	12: MoveLoc[0](loc0: u64)
-	13: LdU64(0)
-	14: Eq
-	15: BrFalse(17)
+	12: Branch(14)
 B5:
-	16: Call bar()
+	13: Call bar()
 B6:
-	17: Ret
+	14: MoveLoc[0](loc0: u64)
+	15: LdU64(0)
+	16: Eq
+	17: BrTrue(19)
+B7:
+	18: Branch(20)
+B8:
+	19: Call bar()
+B9:
+	20: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/testsuite.rs b/third_party/move/move-compiler-v2/tests/testsuite.rs
index 2be787447d562..b688bde9ddee8 100644
--- a/third_party/move/move-compiler-v2/tests/testsuite.rs
+++ b/third_party/move/move-compiler-v2/tests/testsuite.rs
@@ -555,7 +555,7 @@ const TEST_CONFIGS: Lazy<BTreeMap<&str, TestConfig>> = Lazy::new(|| {
             stop_after: StopAfter::BytecodePipeline(Some("uninitialized_use_checker")),
             dump_ast: DumpLevel::None,
             dump_bytecode: DumpLevel::AllStages,
-            dump_bytecode_filter: None,
+            dump_bytecode_filter: Some(vec![INITIAL_BYTECODE_STAGE, "uninitialized_use_checker"]),
         },
         // -- File Format Generation
         // Test without bytecode optimizations enabled
diff --git a/third_party/move/move-compiler-v2/tests/unreachable-code-remover/break_unreachable.exp b/third_party/move/move-compiler-v2/tests/unreachable-code-remover/break_unreachable.exp
index 85964100284ef..ca5f7519139aa 100644
--- a/third_party/move/move-compiler-v2/tests/unreachable-code-remover/break_unreachable.exp
+++ b/third_party/move/move-compiler-v2/tests/unreachable-code-remover/break_unreachable.exp
@@ -71,11 +71,15 @@ fun m::test() {
      # maybe
   6: $t3 := ==($t0, $t4)
      # maybe
-  7: if ($t3) goto 8 else goto 1
+  7: if ($t3) goto 10 else goto 8
      # maybe
-  8: label L2
+  8: label L3
+     # maybe
+  9: goto 1
      # maybe
-  9: return ()
+ 10: label L2
+     # maybe
+ 11: return ()
 }
 
 ============ after UnreachableCodeRemover: ================
@@ -100,9 +104,11 @@ fun m::test() {
   4: $t0 := move($t1)
   5: $t4 := 10
   6: $t3 := ==($t0, $t4)
-  7: if ($t3) goto 8 else goto 1
-  8: label L2
-  9: return ()
+  7: if ($t3) goto 10 else goto 8
+  8: label L3
+  9: goto 1
+ 10: label L2
+ 11: return ()
 }
 
 
diff --git a/third_party/move/move-compiler-v2/tests/unreachable-code-remover/conditional_loop_unreachable.exp b/third_party/move/move-compiler-v2/tests/unreachable-code-remover/conditional_loop_unreachable.exp
index 7d17167abd3d0..39b915dd1b386 100644
--- a/third_party/move/move-compiler-v2/tests/unreachable-code-remover/conditional_loop_unreachable.exp
+++ b/third_party/move/move-compiler-v2/tests/unreachable-code-remover/conditional_loop_unreachable.exp
@@ -62,19 +62,31 @@ fun m::test($t0: bool, $t1: bool) {
      var $t6: u64 [unused]
      var $t7: u64 [unused]
      # maybe
-  0: if ($t0) goto 1 else goto 5
+  0: if ($t0) goto 3 else goto 1
      # maybe
-  1: label L2
+  1: label L9
      # maybe
-  2: if ($t1) goto 3 else goto 5
+  2: goto 11
      # maybe
-  3: label L8
+  3: label L2
      # maybe
-  4: goto 3
+  4: if ($t1) goto 5 else goto 7
      # maybe
-  5: label L1
+  5: label L10
      # maybe
-  6: return ()
+  6: goto 9
+     # maybe
+  7: label L11
+     # maybe
+  8: goto 11
+     # maybe
+  9: label L8
+     # maybe
+ 10: goto 9
+     # maybe
+ 11: label L1
+     # maybe
+ 12: return ()
 }
 
 ============ after UnreachableCodeRemover: ================
@@ -87,13 +99,19 @@ fun m::test($t0: bool, $t1: bool) {
      var $t5: u64 [unused]
      var $t6: u64 [unused]
      var $t7: u64 [unused]
-  0: if ($t0) goto 1 else goto 5
-  1: label L2
-  2: if ($t1) goto 3 else goto 5
-  3: label L8
-  4: goto 3
-  5: label L1
-  6: return ()
+  0: if ($t0) goto 3 else goto 1
+  1: label L9
+  2: goto 11
+  3: label L2
+  4: if ($t1) goto 5 else goto 7
+  5: label L10
+  6: goto 9
+  7: label L11
+  8: goto 11
+  9: label L8
+ 10: goto 9
+ 11: label L1
+ 12: return ()
 }
 
 
diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.exp
index 35fdadd470288..79aa80de12745 100644
--- a/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.exp
+++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.exp
@@ -28,14 +28,16 @@ fun m::foo($t0: bool, $t1: u64): u64 {
      var $t4: u64
      var $t5: u64
   0: $t3 := move($t1)
-  1: if ($t0) goto 2 else goto 5
-  2: label L0
-  3: $t4 := 0
-  4: $t3 := move($t4)
-  5: label L2
-  6: $t5 := 1
-  7: $t2 := +($t3, $t5)
-  8: return $t2
+  1: if ($t0) goto 4 else goto 2
+  2: label L3
+  3: goto 7
+  4: label L0
+  5: $t4 := 0
+  6: $t3 := move($t4)
+  7: label L2
+  8: $t5 := 1
+  9: $t2 := +($t3, $t5)
+ 10: return $t2
 }
 
 ============ after VariableCoalescingAnnotator: ================
@@ -51,26 +53,30 @@ fun m::foo($t0: bool, $t1: u64): u64 {
   0: $t3 := move($t1)
      # live vars: $t0, $t3
      # events: e:$t0
-  1: if ($t0) goto 2 else goto 5
+  1: if ($t0) goto 4 else goto 2
      # live vars: $t3
-  2: label L0
+  2: label L3
+     # live vars: $t3
+  3: goto 7
+     # live vars: $t3
+  4: label L0
      # live vars:
      # events: b:$t4
-  3: $t4 := 0
+  5: $t4 := 0
      # live vars: $t4
      # events: e:$t4
-  4: $t3 := move($t4)
+  6: $t3 := move($t4)
      # live vars: $t3
-  5: label L2
+  7: label L2
      # live vars: $t3
      # events: b:$t5
-  6: $t5 := 1
+  8: $t5 := 1
      # live vars: $t3, $t5
      # events: e:$t3, e:$t5, b:$t2
-  7: $t2 := +($t3, $t5)
+  9: $t2 := +($t3, $t5)
      # live vars: $t2
      # events: e:$t2
-  8: return $t2
+ 10: return $t2
 }
 
 ============ after VariableCoalescingTransformer: ================
@@ -82,14 +88,16 @@ fun m::foo($t0: bool, $t1: u64): u64 {
      var $t4: u64
      var $t5: u64 [unused]
   0: $t1 := move($t1)
-  1: if ($t0) goto 2 else goto 5
-  2: label L0
-  3: $t4 := 0
-  4: $t1 := move($t4)
-  5: label L2
-  6: $t4 := 1
-  7: $t1 := +($t1, $t4)
-  8: return $t1
+  1: if ($t0) goto 4 else goto 2
+  2: label L3
+  3: goto 7
+  4: label L0
+  5: $t4 := 0
+  6: $t1 := move($t4)
+  7: label L2
+  8: $t4 := 1
+  9: $t1 := +($t1, $t4)
+ 10: return $t1
 }
 
 ============ after DeadStoreElimination: ================
@@ -100,14 +108,16 @@ fun m::foo($t0: bool, $t1: u64): u64 {
      var $t3: u64 [unused]
      var $t4: u64
      var $t5: u64 [unused]
-  0: if ($t0) goto 1 else goto 4
-  1: label L0
-  2: $t4 := 0
-  3: $t1 := move($t4)
-  4: label L2
-  5: $t4 := 1
-  6: $t1 := +($t1, $t4)
-  7: return $t1
+  0: if ($t0) goto 3 else goto 1
+  1: label L3
+  2: goto 6
+  3: label L0
+  4: $t4 := 0
+  5: $t1 := move($t4)
+  6: label L2
+  7: $t4 := 1
+  8: $t1 := +($t1, $t4)
+  9: return $t1
 }
 
 
@@ -120,15 +130,17 @@ foo(Arg0: bool, Arg1: u64): u64 /* def_idx: 0 */ {
 L2:	loc0: u64
 B0:
 	0: MoveLoc[0](Arg0: bool)
-	1: BrFalse(4)
+	1: BrTrue(3)
 B1:
-	2: LdU64(0)
-	3: StLoc[1](Arg1: u64)
+	2: Branch(5)
 B2:
-	4: MoveLoc[1](Arg1: u64)
-	5: LdU64(1)
-	6: Add
-	7: Ret
+	3: LdU64(0)
+	4: StLoc[1](Arg1: u64)
+B3:
+	5: MoveLoc[1](Arg1: u64)
+	6: LdU64(1)
+	7: Add
+	8: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.opt.exp
index 35fdadd470288..79aa80de12745 100644
--- a/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.opt.exp
+++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/branch_1.opt.exp
@@ -28,14 +28,16 @@ fun m::foo($t0: bool, $t1: u64): u64 {
      var $t4: u64
      var $t5: u64
   0: $t3 := move($t1)
-  1: if ($t0) goto 2 else goto 5
-  2: label L0
-  3: $t4 := 0
-  4: $t3 := move($t4)
-  5: label L2
-  6: $t5 := 1
-  7: $t2 := +($t3, $t5)
-  8: return $t2
+  1: if ($t0) goto 4 else goto 2
+  2: label L3
+  3: goto 7
+  4: label L0
+  5: $t4 := 0
+  6: $t3 := move($t4)
+  7: label L2
+  8: $t5 := 1
+  9: $t2 := +($t3, $t5)
+ 10: return $t2
 }
 
 ============ after VariableCoalescingAnnotator: ================
@@ -51,26 +53,30 @@ fun m::foo($t0: bool, $t1: u64): u64 {
   0: $t3 := move($t1)
      # live vars: $t0, $t3
      # events: e:$t0
-  1: if ($t0) goto 2 else goto 5
+  1: if ($t0) goto 4 else goto 2
      # live vars: $t3
-  2: label L0
+  2: label L3
+     # live vars: $t3
+  3: goto 7
+     # live vars: $t3
+  4: label L0
      # live vars:
      # events: b:$t4
-  3: $t4 := 0
+  5: $t4 := 0
      # live vars: $t4
      # events: e:$t4
-  4: $t3 := move($t4)
+  6: $t3 := move($t4)
      # live vars: $t3
-  5: label L2
+  7: label L2
      # live vars: $t3
      # events: b:$t5
-  6: $t5 := 1
+  8: $t5 := 1
      # live vars: $t3, $t5
      # events: e:$t3, e:$t5, b:$t2
-  7: $t2 := +($t3, $t5)
+  9: $t2 := +($t3, $t5)
      # live vars: $t2
      # events: e:$t2
-  8: return $t2
+ 10: return $t2
 }
 
 ============ after VariableCoalescingTransformer: ================
@@ -82,14 +88,16 @@ fun m::foo($t0: bool, $t1: u64): u64 {
      var $t4: u64
      var $t5: u64 [unused]
   0: $t1 := move($t1)
-  1: if ($t0) goto 2 else goto 5
-  2: label L0
-  3: $t4 := 0
-  4: $t1 := move($t4)
-  5: label L2
-  6: $t4 := 1
-  7: $t1 := +($t1, $t4)
-  8: return $t1
+  1: if ($t0) goto 4 else goto 2
+  2: label L3
+  3: goto 7
+  4: label L0
+  5: $t4 := 0
+  6: $t1 := move($t4)
+  7: label L2
+  8: $t4 := 1
+  9: $t1 := +($t1, $t4)
+ 10: return $t1
 }
 
 ============ after DeadStoreElimination: ================
@@ -100,14 +108,16 @@ fun m::foo($t0: bool, $t1: u64): u64 {
      var $t3: u64 [unused]
      var $t4: u64
      var $t5: u64 [unused]
-  0: if ($t0) goto 1 else goto 4
-  1: label L0
-  2: $t4 := 0
-  3: $t1 := move($t4)
-  4: label L2
-  5: $t4 := 1
-  6: $t1 := +($t1, $t4)
-  7: return $t1
+  0: if ($t0) goto 3 else goto 1
+  1: label L3
+  2: goto 6
+  3: label L0
+  4: $t4 := 0
+  5: $t1 := move($t4)
+  6: label L2
+  7: $t4 := 1
+  8: $t1 := +($t1, $t4)
+  9: return $t1
 }
 
 
@@ -120,15 +130,17 @@ foo(Arg0: bool, Arg1: u64): u64 /* def_idx: 0 */ {
 L2:	loc0: u64
 B0:
 	0: MoveLoc[0](Arg0: bool)
-	1: BrFalse(4)
+	1: BrTrue(3)
 B1:
-	2: LdU64(0)
-	3: StLoc[1](Arg1: u64)
+	2: Branch(5)
 B2:
-	4: MoveLoc[1](Arg1: u64)
-	5: LdU64(1)
-	6: Add
-	7: Ret
+	3: LdU64(0)
+	4: StLoc[1](Arg1: u64)
+B3:
+	5: MoveLoc[1](Arg1: u64)
+	6: LdU64(1)
+	7: Add
+	8: Ret
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/bug_12068.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/bug_12068.exp
index b7b65fdc22d07..3d253d06f0147 100644
--- a/third_party/move/move-compiler-v2/tests/variable-coalescing/bug_12068.exp
+++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/bug_12068.exp
@@ -49,20 +49,22 @@ fun m::main() {
      var $t6: u64
   0: $t0 := 0
   1: $t1 := true
-  2: if ($t1) goto 3 else goto 7
-  3: label L2
-  4: $t3 := 1
-  5: $t2 := +($t0, $t3)
-  6: $t0 := move($t2)
-  7: label L1
-  8: $t5 := 1
-  9: $t4 := ==($t0, $t5)
- 10: if ($t4) goto 11 else goto 13
- 11: label L5
- 12: return ()
- 13: label L6
- 14: $t6 := 42
- 15: abort($t6)
+  2: if ($t1) goto 5 else goto 3
+  3: label L7
+  4: goto 9
+  5: label L2
+  6: $t3 := 1
+  7: $t2 := +($t0, $t3)
+  8: $t0 := move($t2)
+  9: label L1
+ 10: $t5 := 1
+ 11: $t4 := ==($t0, $t5)
+ 12: if ($t4) goto 13 else goto 15
+ 13: label L5
+ 14: return ()
+ 15: label L6
+ 16: $t6 := 42
+ 17: abort($t6)
 }
 
 ============ after VariableCoalescingAnnotator: ================
@@ -84,41 +86,45 @@ fun m::main() {
   1: $t1 := true
      # live vars: $t0, $t1
      # events: e:$t1
-  2: if ($t1) goto 3 else goto 7
+  2: if ($t1) goto 5 else goto 3
      # live vars: $t0
-  3: label L2
+  3: label L7
+     # live vars: $t0
+  4: goto 9
+     # live vars: $t0
+  5: label L2
      # live vars: $t0
      # events: b:$t3
-  4: $t3 := 1
+  6: $t3 := 1
      # live vars: $t0, $t3
      # events: e:$t3, b:$t2
-  5: $t2 := +($t0, $t3)
+  7: $t2 := +($t0, $t3)
      # live vars: $t2
      # events: e:$t2
-  6: $t0 := move($t2)
+  8: $t0 := move($t2)
      # live vars: $t0
-  7: label L1
+  9: label L1
      # live vars: $t0
      # events: b:$t5
-  8: $t5 := 1
+ 10: $t5 := 1
      # live vars: $t0, $t5
      # events: e:$t0, e:$t5, b:$t4
-  9: $t4 := ==($t0, $t5)
+ 11: $t4 := ==($t0, $t5)
      # live vars: $t4
      # events: e:$t4
- 10: if ($t4) goto 11 else goto 13
+ 12: if ($t4) goto 13 else goto 15
      # live vars:
- 11: label L5
+ 13: label L5
      # live vars:
- 12: return ()
+ 14: return ()
      # live vars:
- 13: label L6
+ 15: label L6
      # live vars:
      # events: b:$t6
- 14: $t6 := 42
+ 16: $t6 := 42
      # live vars: $t6
      # events: e:$t6
- 15: abort($t6)
+ 17: abort($t6)
 }
 
 ============ after VariableCoalescingTransformer: ================
@@ -134,20 +140,22 @@ fun m::main() {
      var $t6: u64 [unused]
   0: $t0 := 0
   1: $t1 := true
-  2: if ($t1) goto 3 else goto 7
-  3: label L2
-  4: $t3 := 1
-  5: $t3 := +($t0, $t3)
-  6: $t0 := move($t3)
-  7: label L1
-  8: $t3 := 1
-  9: $t1 := ==($t0, $t3)
- 10: if ($t1) goto 11 else goto 13
- 11: label L5
- 12: return ()
- 13: label L6
- 14: $t0 := 42
- 15: abort($t0)
+  2: if ($t1) goto 5 else goto 3
+  3: label L7
+  4: goto 9
+  5: label L2
+  6: $t3 := 1
+  7: $t3 := +($t0, $t3)
+  8: $t0 := move($t3)
+  9: label L1
+ 10: $t3 := 1
+ 11: $t1 := ==($t0, $t3)
+ 12: if ($t1) goto 13 else goto 15
+ 13: label L5
+ 14: return ()
+ 15: label L6
+ 16: $t0 := 42
+ 17: abort($t0)
 }
 
 ============ after DeadStoreElimination: ================
@@ -163,20 +171,22 @@ fun m::main() {
      var $t6: u64 [unused]
   0: $t0 := 0
   1: $t1 := true
-  2: if ($t1) goto 3 else goto 7
-  3: label L2
-  4: $t3 := 1
-  5: $t3 := +($t0, $t3)
-  6: $t0 := move($t3)
-  7: label L1
-  8: $t3 := 1
-  9: $t1 := ==($t0, $t3)
- 10: if ($t1) goto 11 else goto 13
- 11: label L5
- 12: return ()
- 13: label L6
- 14: $t0 := 42
- 15: abort($t0)
+  2: if ($t1) goto 5 else goto 3
+  3: label L7
+  4: goto 9
+  5: label L2
+  6: $t3 := 1
+  7: $t3 := +($t0, $t3)
+  8: $t0 := move($t3)
+  9: label L1
+ 10: $t3 := 1
+ 11: $t1 := ==($t0, $t3)
+ 12: if ($t1) goto 13 else goto 15
+ 13: label L5
+ 14: return ()
+ 15: label L6
+ 16: $t0 := 42
+ 17: abort($t0)
 }
 
 
@@ -190,16 +200,25 @@ L0:	loc0: u64
 L1:	loc1: u64
 B0:
 	0: LdU64(0)
-	1: LdU64(1)
-	2: Add
-	3: LdU64(1)
-	4: Eq
-	5: BrFalse(7)
+	1: StLoc[0](loc0: u64)
+	2: Branch(4)
 B1:
-	6: Ret
+	3: Branch(8)
 B2:
-	7: LdU64(42)
-	8: Abort
+	4: MoveLoc[0](loc0: u64)
+	5: LdU64(1)
+	6: Add
+	7: StLoc[0](loc0: u64)
+B3:
+	8: MoveLoc[0](loc0: u64)
+	9: LdU64(1)
+	10: Eq
+	11: BrFalse(13)
+B4:
+	12: Ret
+B5:
+	13: LdU64(42)
+	14: Abort
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/tests/variable-coalescing/bug_12068.opt.exp b/third_party/move/move-compiler-v2/tests/variable-coalescing/bug_12068.opt.exp
index b7b65fdc22d07..3d253d06f0147 100644
--- a/third_party/move/move-compiler-v2/tests/variable-coalescing/bug_12068.opt.exp
+++ b/third_party/move/move-compiler-v2/tests/variable-coalescing/bug_12068.opt.exp
@@ -49,20 +49,22 @@ fun m::main() {
      var $t6: u64
   0: $t0 := 0
   1: $t1 := true
-  2: if ($t1) goto 3 else goto 7
-  3: label L2
-  4: $t3 := 1
-  5: $t2 := +($t0, $t3)
-  6: $t0 := move($t2)
-  7: label L1
-  8: $t5 := 1
-  9: $t4 := ==($t0, $t5)
- 10: if ($t4) goto 11 else goto 13
- 11: label L5
- 12: return ()
- 13: label L6
- 14: $t6 := 42
- 15: abort($t6)
+  2: if ($t1) goto 5 else goto 3
+  3: label L7
+  4: goto 9
+  5: label L2
+  6: $t3 := 1
+  7: $t2 := +($t0, $t3)
+  8: $t0 := move($t2)
+  9: label L1
+ 10: $t5 := 1
+ 11: $t4 := ==($t0, $t5)
+ 12: if ($t4) goto 13 else goto 15
+ 13: label L5
+ 14: return ()
+ 15: label L6
+ 16: $t6 := 42
+ 17: abort($t6)
 }
 
 ============ after VariableCoalescingAnnotator: ================
@@ -84,41 +86,45 @@ fun m::main() {
   1: $t1 := true
      # live vars: $t0, $t1
      # events: e:$t1
-  2: if ($t1) goto 3 else goto 7
+  2: if ($t1) goto 5 else goto 3
      # live vars: $t0
-  3: label L2
+  3: label L7
+     # live vars: $t0
+  4: goto 9
+     # live vars: $t0
+  5: label L2
      # live vars: $t0
      # events: b:$t3
-  4: $t3 := 1
+  6: $t3 := 1
      # live vars: $t0, $t3
      # events: e:$t3, b:$t2
-  5: $t2 := +($t0, $t3)
+  7: $t2 := +($t0, $t3)
      # live vars: $t2
      # events: e:$t2
-  6: $t0 := move($t2)
+  8: $t0 := move($t2)
      # live vars: $t0
-  7: label L1
+  9: label L1
      # live vars: $t0
      # events: b:$t5
-  8: $t5 := 1
+ 10: $t5 := 1
      # live vars: $t0, $t5
      # events: e:$t0, e:$t5, b:$t4
-  9: $t4 := ==($t0, $t5)
+ 11: $t4 := ==($t0, $t5)
      # live vars: $t4
      # events: e:$t4
- 10: if ($t4) goto 11 else goto 13
+ 12: if ($t4) goto 13 else goto 15
      # live vars:
- 11: label L5
+ 13: label L5
      # live vars:
- 12: return ()
+ 14: return ()
      # live vars:
- 13: label L6
+ 15: label L6
      # live vars:
      # events: b:$t6
- 14: $t6 := 42
+ 16: $t6 := 42
      # live vars: $t6
      # events: e:$t6
- 15: abort($t6)
+ 17: abort($t6)
 }
 
 ============ after VariableCoalescingTransformer: ================
@@ -134,20 +140,22 @@ fun m::main() {
      var $t6: u64 [unused]
   0: $t0 := 0
   1: $t1 := true
-  2: if ($t1) goto 3 else goto 7
-  3: label L2
-  4: $t3 := 1
-  5: $t3 := +($t0, $t3)
-  6: $t0 := move($t3)
-  7: label L1
-  8: $t3 := 1
-  9: $t1 := ==($t0, $t3)
- 10: if ($t1) goto 11 else goto 13
- 11: label L5
- 12: return ()
- 13: label L6
- 14: $t0 := 42
- 15: abort($t0)
+  2: if ($t1) goto 5 else goto 3
+  3: label L7
+  4: goto 9
+  5: label L2
+  6: $t3 := 1
+  7: $t3 := +($t0, $t3)
+  8: $t0 := move($t3)
+  9: label L1
+ 10: $t3 := 1
+ 11: $t1 := ==($t0, $t3)
+ 12: if ($t1) goto 13 else goto 15
+ 13: label L5
+ 14: return ()
+ 15: label L6
+ 16: $t0 := 42
+ 17: abort($t0)
 }
 
 ============ after DeadStoreElimination: ================
@@ -163,20 +171,22 @@ fun m::main() {
      var $t6: u64 [unused]
   0: $t0 := 0
   1: $t1 := true
-  2: if ($t1) goto 3 else goto 7
-  3: label L2
-  4: $t3 := 1
-  5: $t3 := +($t0, $t3)
-  6: $t0 := move($t3)
-  7: label L1
-  8: $t3 := 1
-  9: $t1 := ==($t0, $t3)
- 10: if ($t1) goto 11 else goto 13
- 11: label L5
- 12: return ()
- 13: label L6
- 14: $t0 := 42
- 15: abort($t0)
+  2: if ($t1) goto 5 else goto 3
+  3: label L7
+  4: goto 9
+  5: label L2
+  6: $t3 := 1
+  7: $t3 := +($t0, $t3)
+  8: $t0 := move($t3)
+  9: label L1
+ 10: $t3 := 1
+ 11: $t1 := ==($t0, $t3)
+ 12: if ($t1) goto 13 else goto 15
+ 13: label L5
+ 14: return ()
+ 15: label L6
+ 16: $t0 := 42
+ 17: abort($t0)
 }
 
 
@@ -190,16 +200,25 @@ L0:	loc0: u64
 L1:	loc1: u64
 B0:
 	0: LdU64(0)
-	1: LdU64(1)
-	2: Add
-	3: LdU64(1)
-	4: Eq
-	5: BrFalse(7)
+	1: StLoc[0](loc0: u64)
+	2: Branch(4)
 B1:
-	6: Ret
+	3: Branch(8)
 B2:
-	7: LdU64(42)
-	8: Abort
+	4: MoveLoc[0](loc0: u64)
+	5: LdU64(1)
+	6: Add
+	7: StLoc[0](loc0: u64)
+B3:
+	8: MoveLoc[0](loc0: u64)
+	9: LdU64(1)
+	10: Eq
+	11: BrFalse(13)
+B4:
+	12: Ret
+B5:
+	13: LdU64(42)
+	14: Abort
 }
 }
 ============ bytecode verification succeeded ========
diff --git a/third_party/move/move-compiler-v2/transactional-tests/tests/no-v1-comparison/enum/bug_14733_match_critical_edge.exp b/third_party/move/move-compiler-v2/transactional-tests/tests/no-v1-comparison/enum/bug_14733_match_critical_edge.exp
new file mode 100644
index 0000000000000..ec874a527383d
--- /dev/null
+++ b/third_party/move/move-compiler-v2/transactional-tests/tests/no-v1-comparison/enum/bug_14733_match_critical_edge.exp
@@ -0,0 +1,22 @@
+processed 8 tasks
+
+task 1 'run'. lines 73-73:
+return values: 22
+
+task 2 'run'. lines 75-75:
+return values: 0
+
+task 3 'run'. lines 77-77:
+return values: 10
+
+task 4 'run'. lines 79-79:
+return values: 21
+
+task 5 'run'. lines 81-81:
+return values: 43
+
+task 6 'run'. lines 83-83:
+return values: 25
+
+task 7 'run'. lines 85-85:
+return values: 15
diff --git a/third_party/move/move-compiler-v2/transactional-tests/tests/no-v1-comparison/enum/bug_14733_match_critical_edge.move b/third_party/move/move-compiler-v2/transactional-tests/tests/no-v1-comparison/enum/bug_14733_match_critical_edge.move
new file mode 100644
index 0000000000000..6eb808a122594
--- /dev/null
+++ b/third_party/move/move-compiler-v2/transactional-tests/tests/no-v1-comparison/enum/bug_14733_match_critical_edge.move
@@ -0,0 +1,85 @@
+// This source tests various scenarios of matches which introduce critical edges, which
+// are eliminated by the split-critical-edge-processor. This kind of matches
+// are also the only kind of code which can introduce those edges, so we are also
+// testing functionality of the processor here.
+
+//# publish
+module 0x815::m {
+    enum Entity has drop {
+        Person { id: u64 },
+        Institution { id: u64, admin: Admin }
+    }
+
+    enum Admin has drop {
+        Superuser,
+        User(u64)
+    }
+
+    // Ensure function is inlined so we create nested matches in the next one.
+    inline fun id(self: &Entity): u64 {
+        match (self) {
+            Person{id} if *id > 10 => *id,
+            Institution{id, ..} => *id,
+            _ => 0
+        }
+    }
+
+    fun admin_id(self: &Entity): u64 {
+        match (self) {
+            Institution{admin: Admin::Superuser, ..} => 1 + self.id(),
+            Institution{admin: Admin::User(id), ..} if *id > 10 => *id + self.id(),
+            Institution{admin: Admin::User(id), ..} if  *id <= 10 => self.id() + 5,
+            _ => self.id()
+
+        }
+    }
+
+    fun test1(): u64 {
+        let e = Entity::Person{id: 22};
+        e.id()
+    }
+
+    fun test2(): u64 {
+        let e = Entity::Person{id: 10};
+        e.id()
+    }
+
+    fun test3(): u64 {
+        let e = Entity::Institution { id: 10, admin: Admin::Superuser };
+        e.id()
+    }
+
+    fun test4(): u64 {
+        let e = Entity::Institution{id: 20, admin: Admin::Superuser};
+        e.admin_id()
+    }
+
+    fun test5(): u64 {
+        let e = Entity::Institution{id: 20, admin: Admin::User(23)};
+        e.admin_id()
+    }
+
+    fun test6(): u64 {
+        let e = Entity::Institution{id: 20, admin: Admin::User(8)};
+        e.admin_id()
+    }
+
+    fun test7(): u64 {
+        let e = Entity::Person{id: 15};
+        e.admin_id()
+    }
+}
+
+//# run 0x815::m::test1
+
+//# run 0x815::m::test2
+
+//# run 0x815::m::test3
+
+//# run 0x815::m::test4
+
+//# run 0x815::m::test5
+
+//# run 0x815::m::test6
+
+//# run 0x815::m::test7
diff --git a/third_party/move/move-model/bytecode/ast-generator-tests/tests/match.exp b/third_party/move/move-model/bytecode/ast-generator-tests/tests/match.exp
index 35705886bb3e5..5598f2eda8d9b 100644
--- a/third_party/move/move-model/bytecode/ast-generator-tests/tests/match.exp
+++ b/third_party/move/move-model/bytecode/ast-generator-tests/tests/match.exp
@@ -163,35 +163,35 @@ fun m::id2($t0|self: 0x815::m::Entity): u64 {
   2: $t4 := copy($t1)
   3: $t5 := test_variant 0x815::m::Entity::Person($t4)
   4: if ($t5) goto 5 else goto 19
-  5: label L1
+  5: label L0
   6: $t6 := copy($t1)
   7: $t7 := borrow_variant_field<0x815::m::Entity::Person>.id($t6)
   8: $t8 := read_ref($t7)
   9: $t9 := 0
  10: $t10 := >($t8, $t9)
  11: if ($t10) goto 12 else goto 19
- 12: label L2
+ 12: label L3
  13: $t11 := move($t1)
  14: drop($t11)
  15: $t12 := move($t0)
  16: $t13 := unpack_variant 0x815::m::Entity::Person($t12)
  17: $t2 := $t13
  18: goto 33
- 19: label L0
+ 19: label L2
  20: $t14 := move($t1)
  21: $t15 := test_variant 0x815::m::Entity::Institution($t14)
  22: if ($t15) goto 23 else goto 29
- 23: label L5
+ 23: label L7
  24: $t16 := move($t0)
  25: ($t17, $t18) := unpack_variant 0x815::m::Entity::Institution($t16)
  26: drop($t18)
  27: $t2 := $t17
  28: goto 33
- 29: label L4
+ 29: label L6
  30: $t19 := 0
  31: $t2 := $t19
  32: goto 33
- 33: label L3
+ 33: label L5
  34: $t20 := move($t2)
  35: return $t20
 }
diff --git a/third_party/move/move-prover/tests/sources/functional/enum_abort.v2_exp b/third_party/move/move-prover/tests/sources/functional/enum_abort.v2_exp
index 4f2cdf6e909ca..ae88dbefbd545 100644
--- a/third_party/move/move-prover/tests/sources/functional/enum_abort.v2_exp
+++ b/third_party/move/move-prover/tests/sources/functional/enum_abort.v2_exp
@@ -103,7 +103,6 @@ error: abort not covered by any of the `aborts_if` clauses
     =         <redacted> = <redacted>
     =     at tests/sources/functional/enum_abort.move:122: test_match_abort
     =         _z = <redacted>
-    =         <redacted> = <redacted>
     =     at tests/sources/functional/enum_abort.move:122: test_match_abort
     =         <redacted> = <redacted>
     =     at tests/sources/functional/enum_abort.move:122: test_match_abort