diff options
-rw-r--r-- | src/passes/GUFA.cpp | 1 | ||||
-rw-r--r-- | test/lit/passes/gufa-refs.wast | 50 | ||||
-rw-r--r-- | test/lit/passes/gufa-tnh.wast | 6 |
3 files changed, 54 insertions, 3 deletions
diff --git a/src/passes/GUFA.cpp b/src/passes/GUFA.cpp index 0bcb5eb80..513b2cf3d 100644 --- a/src/passes/GUFA.cpp +++ b/src/passes/GUFA.cpp @@ -284,6 +284,7 @@ struct GUFAOptimizer // a cast. However, to be careful with code size, we only refine existing // here. See addNewCasts() for where we add entirely new casts. curr->type = inferredType; + optimized = true; } // Apply the usual optimizations as well, such as potentially replacing this diff --git a/test/lit/passes/gufa-refs.wast b/test/lit/passes/gufa-refs.wast index 3e7530926..11a72b644 100644 --- a/test/lit/passes/gufa-refs.wast +++ b/test/lit/passes/gufa-refs.wast @@ -5730,3 +5730,53 @@ ) ) ) + +(module + ;; CHECK: (type $A (struct )) + (type $A (struct)) + + ;; CHECK: (type $1 (func)) + + ;; CHECK: (func $func (type $1) + ;; CHECK-NEXT: (local $temp anyref) + ;; CHECK-NEXT: (local.set $temp + ;; CHECK-NEXT: (struct.new_default $A) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block $label (result (ref null $A)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (br_on_cast $label (ref $A) (ref $A) + ;; CHECK-NEXT: (ref.cast (ref $A) + ;; CHECK-NEXT: (local.get $temp) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $func + (local $temp anyref) + ;; Write an $A into the anyref local. + (local.set $temp + (struct.new $A) + ) + (drop + (block $label (result anyref) + (drop + (br_on_cast $label anyref (ref struct) + ;; This cast can be refined since we know the input is $A. After we + ;; do that, we must refinalize, as the br_on_cast's types must be + ;; valid - specifically, we can't end up with the input type being + ;; $A and the output type still being (ref struct), as the output + ;; type must be a subtype. After refinalizing, both will become $A. + (ref.cast anyref + (local.get $temp) + ) + ) + ) + (ref.null none) + ) + ) + ) +) diff --git a/test/lit/passes/gufa-tnh.wast b/test/lit/passes/gufa-tnh.wast index fb9348365..3a9c77a30 100644 --- a/test/lit/passes/gufa-tnh.wast +++ b/test/lit/passes/gufa-tnh.wast @@ -686,7 +686,7 @@ ;; CHECK-NEXT: (local.get $any) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (block (result (ref $A)) + ;; CHECK-NEXT: (block (result (ref $B)) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (return) @@ -695,7 +695,7 @@ ;; CHECK-NEXT: (local.get $any) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (block (result (ref $A)) + ;; CHECK-NEXT: (block (result (ref $B)) ;; CHECK-NEXT: (ref.cast (ref $B) ;; CHECK-NEXT: (local.get $any) ;; CHECK-NEXT: ) @@ -794,7 +794,7 @@ ;; CHECK-NEXT: (local.get $any) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (block (result (ref $A)) + ;; CHECK-NEXT: (block (result (ref $B)) ;; CHECK-NEXT: (ref.cast (ref $B) ;; CHECK-NEXT: (local.get $any) ;; CHECK-NEXT: ) |