Skip to content

Commit

Permalink
[Outlining] Test single and multivalue return (#6120)
Browse files Browse the repository at this point in the history
Adds two tests, creates an outlined function that returns a single value and creates an outlined function that returns multivalue.
  • Loading branch information
ashleynh authored Nov 17, 2023
1 parent 7ae1185 commit 67f2fdc
Showing 1 changed file with 119 additions and 27 deletions.
146 changes: 119 additions & 27 deletions test/lit/passes/outlining.wast
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt --outlining -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt --outlining -S -all -o - | filecheck %s

;; TODO: Add a test that creates an outlined function with one return value
;; TODO: Add a test that creates an outlined function that returns multiple values
;; TODO: Add a test that fails to outline a single control flow that repeats


Expand All @@ -12,7 +10,7 @@

;; CHECK: (type $1 (func (param i32)))

;; CHECK: (func $outline$ (param $0 i32)
;; CHECK: (func $outline$ (type $1) (param $0 i32)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: )
Expand All @@ -24,7 +22,7 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )

;; CHECK: (func $a (result i32)
;; CHECK: (func $a (type $0) (result i32)
;; CHECK-NEXT: (call $outline$
;; CHECK-NEXT: (i32.const 7)
;; CHECK-NEXT: )
Expand All @@ -46,7 +44,7 @@
(i32.const 4)
)
)
;; CHECK: (func $b (result i32)
;; CHECK: (func $b (type $0) (result i32)
;; CHECK-NEXT: (call $outline$
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
Expand Down Expand Up @@ -74,7 +72,7 @@
(module
;; CHECK: (type $0 (func))

;; CHECK: (func $outline$
;; CHECK: (func $outline$ (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
Expand All @@ -83,7 +81,7 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )

;; CHECK: (func $a
;; CHECK: (func $a (type $0)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
(func $a
Expand All @@ -94,7 +92,7 @@
(i32.const 2)
)
)
;; CHECK: (func $b
;; CHECK: (func $b (type $0)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
(func $b
Expand All @@ -112,7 +110,7 @@
(module
;; CHECK: (type $0 (func))

;; CHECK: (func $outline$
;; CHECK: (func $outline$ (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
Expand All @@ -127,7 +125,7 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )

;; CHECK: (func $a
;; CHECK: (func $a (type $0)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 6)
Expand All @@ -150,7 +148,7 @@
(i32.const 6)
)
)
;; CHECK: (func $b
;; CHECK: (func $b (type $0)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 7)
Expand Down Expand Up @@ -180,7 +178,7 @@
(module
;; CHECK: (type $0 (func))

;; CHECK: (func $outline$
;; CHECK: (func $outline$ (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.add
;; CHECK-NEXT: (i32.const 0)
Expand All @@ -189,7 +187,7 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )

;; CHECK: (func $outline$_4
;; CHECK: (func $outline$_4 (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.sub
;; CHECK-NEXT: (i32.const 3)
Expand All @@ -198,7 +196,7 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )

;; CHECK: (func $a
;; CHECK: (func $a (type $0)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: (call $outline$_4)
;; CHECK-NEXT: )
Expand All @@ -216,7 +214,7 @@
)
)
)
;; CHECK: (func $b
;; CHECK: (func $b (type $0)
;; CHECK-NEXT: (call $outline$_4)
;; CHECK-NEXT: )
(func $b
Expand All @@ -227,7 +225,7 @@
)
)
)
;; CHECK: (func $c
;; CHECK: (func $c (type $0)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
(func $c
Expand All @@ -246,13 +244,13 @@

;; CHECK: (type $1 (func))

;; CHECK: (func $outline$
;; CHECK: (func $outline$ (type $1)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 10)
;; CHECK-NEXT: )
;; CHECK-NEXT: )

;; CHECK: (func $a (param $0 i32)
;; CHECK: (func $a (type $0) (param $0 i32)
;; CHECK-NEXT: (if
;; CHECK-NEXT: (i32.eqz
;; CHECK-NEXT: (local.get $0)
Expand All @@ -270,7 +268,7 @@
)
)
)
;; CHECK: (func $b (param $0 i32)
;; CHECK: (func $b (type $0) (param $0 i32)
;; CHECK-NEXT: (if
;; CHECK-NEXT: (i32.eqz
;; CHECK-NEXT: (local.get $0)
Expand All @@ -294,7 +292,7 @@
(module
;; CHECK: (type $0 (func (param i32)))

;; CHECK: (func $a (param $0 i32)
;; CHECK: (func $a (type $0) (param $0 i32)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.add
;; CHECK-NEXT: (local.get $0)
Expand All @@ -310,7 +308,7 @@
)
)
)
;; CHECK: (func $b (param $0 i32)
;; CHECK: (func $b (type $0) (param $0 i32)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.add
;; CHECK-NEXT: (local.get $0)
Expand All @@ -332,7 +330,7 @@
(module
;; CHECK: (type $0 (func))

;; CHECK: (func $a
;; CHECK: (func $a (type $0)
;; CHECK-NEXT: (local $i i32)
;; CHECK-NEXT: (local.set $i
;; CHECK-NEXT: (i32.const 7)
Expand All @@ -344,7 +342,7 @@
(i32.const 7)
)
)
;; CHECK: (func $b
;; CHECK: (func $b (type $0)
;; CHECK-NEXT: (local $i i32)
;; CHECK-NEXT: (local.set $i
;; CHECK-NEXT: (i32.const 7)
Expand All @@ -362,7 +360,7 @@
(module
;; CHECK: (type $0 (func))

;; CHECK: (func $a
;; CHECK: (func $a (type $0)
;; CHECK-NEXT: (block $label1
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 4)
Expand Down Expand Up @@ -392,7 +390,7 @@
(module
;; CHECK: (type $0 (func (result i32)))

;; CHECK: (func $a (result i32)
;; CHECK: (func $a (type $0) (result i32)
;; CHECK-NEXT: (return
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: )
Expand All @@ -402,7 +400,7 @@
(i32.const 2)
)
)
;; CHECK: (func $b (result i32)
;; CHECK: (func $b (type $0) (result i32)
;; CHECK-NEXT: (return
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: )
Expand All @@ -413,3 +411,97 @@
)
)
)

;; Test that an outlined function is created with one return value.
(module
;; CHECK: (type $0 (func (result i32)))

;; CHECK: (func $outline$ (type $0) (result i32)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )

;; CHECK: (func $a (type $0) (result i32)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
(func $a (result i32)
(drop
(i32.const 0)
)
(i32.const 1)
)
;; CHECK: (func $b (type $0) (result i32)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
(func $b (result i32)
(drop
(i32.const 0)
)
(i32.const 1)
)
)

;; Test that an outlined function is created with multiple return values.
(module
;; CHECK: (type $0 (func (result i32 i32)))

;; CHECK: (type $1 (func))

;; CHECK: (func $outline$ (type $0) (result i32 i32)
;; CHECK-NEXT: (tuple.make
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )

;; CHECK: (func $a (type $1)
;; CHECK-NEXT: (local $scratch (i32 i32))
;; CHECK-NEXT: (local $scratch_1 (i32 i32))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.add
;; CHECK-NEXT: (block (result i32)
;; CHECK-NEXT: (local.set $scratch
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
;; CHECK-NEXT: (tuple.extract 0
;; CHECK-NEXT: (local.get $scratch)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (tuple.extract 1
;; CHECK-NEXT: (local.get $scratch)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.mul
;; CHECK-NEXT: (block (result i32)
;; CHECK-NEXT: (local.set $scratch_1
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
;; CHECK-NEXT: (tuple.extract 0
;; CHECK-NEXT: (local.get $scratch_1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (tuple.extract 1
;; CHECK-NEXT: (local.get $scratch_1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $a
(drop
(i32.add
(i32.const 0)
(i32.const 1)
)
)
(drop
(i32.mul
(i32.const 0)
(i32.const 1)
)
)
)
)

0 comments on commit 67f2fdc

Please sign in to comment.