From 3ac02b6d3cc5bc3ff6cfe57df312b2677ca83d75 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Tue, 18 Dec 2018 09:27:18 -0800 Subject: Fold multi-value results properly (#984) Expressions need to be treated specially when folding an expression with a result count > 1. Since the expression cannot be split, we can only include it as a child of another expression if all of its values are used, for example: ``` (func $dup (result i32 i32) ...) (call $dup) ;; produces two values (i32.add) ;; consumes two values ``` --- test/roundtrip/fold-multi.txt | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/roundtrip/fold-multi.txt (limited to 'test/roundtrip') diff --git a/test/roundtrip/fold-multi.txt b/test/roundtrip/fold-multi.txt new file mode 100644 index 00000000..55a6a49f --- /dev/null +++ b/test/roundtrip/fold-multi.txt @@ -0,0 +1,50 @@ +;;; TOOL: run-roundtrip +;;; ARGS: --stdout --fold-exprs --enable-multi-value +(module + (func $dup (result i32 i32) + i32.const 0 + i32.const 1 + ) + + (func $fold-two (result i32) + call $dup + i32.add + ) + + (func $cant-fold (result i32) + call $dup + i32.const 1 + i32.add + drop + ) + + (func $partial-fold (result i32) + call $dup + call $dup + i32.add + i32.sub + drop + ) +) +(;; STDOUT ;;; +(module + (type (;0;) (func (result i32 i32))) + (type (;1;) (func (result i32))) + (func (;0;) (type 0) (result i32 i32) + (i32.const 0) + (i32.const 1)) + (func (;1;) (type 1) (result i32) + (i32.add + (call 0))) + (func (;2;) (type 1) (result i32) + (call 0) + (i32.const 1) + (i32.add) + (drop)) + (func (;3;) (type 1) (result i32) + (call 0) + (i32.add + (call 0)) + (i32.sub) + (drop))) +;;; STDOUT ;;) -- cgit v1.2.3