diff options
23 files changed, 536 insertions, 223 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 31b28f1e2..649b32196 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -952,12 +952,16 @@ class S2WasmBuilder { bstack.pop_back(); } else if (match("br")) { auto curr = allocator.alloc<Break>(); + bool hasCondition = false; if (*s == '_') { mustMatch("_if"); - curr->condition = getInput(); - skipComma(); + hasCondition = true; } curr->name = getBranchLabel(getInt()); + if (hasCondition) { + skipComma(); + curr->condition = getInput(); + } addToBlock(curr); } else if (match("call")) { makeCall(none); diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 440689ea0..2c884a4f5 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -663,12 +663,12 @@ assert(0); o << int8_t(curr->condition ? BinaryConsts::BrIf : BinaryConsts::Br); int offset = getBreakIndex(curr->name); o << int8_t(offset); - if (curr->condition) recurse(curr->condition); if (curr->value) { recurse(curr->value); } else { visitNop(nullptr); } + if (curr->condition) recurse(curr->condition); } void visitSwitch(Switch *curr) { if (debug) std::cerr << "zz node: Switch" << std::endl; @@ -1356,8 +1356,8 @@ public: if (debug) std::cerr << "zz node: Break" << std::endl; auto offset = getInt8(); curr->name = getBreakName(offset); - if (code == BinaryConsts::BrIf) readExpression(curr->condition); readExpression(curr->value); + if (code == BinaryConsts::BrIf) readExpression(curr->condition); } void visitSwitch(Switch *curr) { if (debug) std::cerr << "zz node: Switch" << std::endl; diff --git a/src/wasm.h b/src/wasm.h index 20a7b34ef..e30a891b9 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -501,13 +501,13 @@ public: class Break : public Expression { public: - Break() : Expression(BreakId), condition(nullptr), value(nullptr) { + Break() : Expression(BreakId), value(nullptr), condition(nullptr) { type = unreachable; } - Expression *condition; Name name; Expression *value; + Expression *condition; std::ostream& doPrint(std::ostream &o, unsigned indent) { if (condition) { diff --git a/test/dot_s/basics.s b/test/dot_s/basics.s index a47765778..69a057f9b 100644 --- a/test/dot_s/basics.s +++ b/test/dot_s/basics.s @@ -20,7 +20,7 @@ main: # @main i32.ne $push10=, $pop8, $pop9 block block - br_if $pop10, 0 + br_if 0, $pop10 .LBB0_1: # %.preheader # =>This Inner Loop Header: Depth=1 loop @@ -32,7 +32,7 @@ main: # @main i32.const $push16=, 3 i32.ne $push17=, $pop15, $pop16 block - br_if $pop17, 0 + br_if 0, $pop17 # BB#2: # in Loop: Header=.LBB0_1 Depth=1 i32.const $push18=, 111 i32.rem_s $push19=, $0, $pop18 @@ -42,7 +42,7 @@ main: # @main i32.rem_s $push21=, $0, $pop20 i32.const $push22=, 0 i32.eq $push23=, $pop21, $pop22 - br_if $pop23, 2 + br_if 2, $pop23 br 0 end_loop end_block diff --git a/test/dot_s/bcp-1.s b/test/dot_s/bcp-1.s index c27542eef..2db6387f5 100644 --- a/test/dot_s/bcp-1.s +++ b/test/dot_s/bcp-1.s @@ -238,89 +238,89 @@ main: # @main block i32.load $push0=, bad_t0($0) i32.call_indirect $push1=, $pop0 - br_if $pop1, 0 # 0: down to label0 + br_if 0, $pop1 # 0: down to label0 # BB#1: # %for.cond i32.load $push2=, bad_t0+4($0) i32.call_indirect $push3=, $pop2 - br_if $pop3, 0 # 0: down to label0 + br_if 0, $pop3 # 0: down to label0 # BB#2: # %for.cond.1 i32.load $push4=, bad_t0+8($0) i32.call_indirect $push5=, $pop4 - br_if $pop5, 0 # 0: down to label0 + br_if 0, $pop5 # 0: down to label0 # BB#3: # %for.cond.2 i32.load $push6=, bad_t0+12($0) i32.call_indirect $push7=, $pop6 - br_if $pop7, 0 # 0: down to label0 + br_if 0, $pop7 # 0: down to label0 # BB#4: # %for.cond.3 i32.load $push8=, bad_t0+16($0) i32.call_indirect $push9=, $pop8 - br_if $pop9, 0 # 0: down to label0 + br_if 0, $pop9 # 0: down to label0 # BB#5: # %for.cond.4 i32.load $push10=, bad_t0+20($0) i32.call_indirect $push11=, $pop10 - br_if $pop11, 0 # 0: down to label0 + br_if 0, $pop11 # 0: down to label0 # BB#6: # %for.cond.5 i32.load $1=, bad_t1($0) i32.const $2=, 1 block i32.call_indirect $push12=, $1, $2 - br_if $pop12, 0 # 0: down to label1 + br_if 0, $pop12 # 0: down to label1 # BB#7: # %for.cond1 i32.load $push13=, bad_t1+4($0) i32.call_indirect $push14=, $pop13, $2 - br_if $pop14, 0 # 0: down to label1 + br_if 0, $pop14 # 0: down to label1 # BB#8: # %for.cond1.1 i32.load $push15=, bad_t1+8($0) i32.call_indirect $push16=, $pop15, $2 - br_if $pop16, 0 # 0: down to label1 + br_if 0, $pop16 # 0: down to label1 # BB#9: # %for.cond1.2 i32.load $1=, bad_t2($0) i32.const $2=, .L.str block i32.call_indirect $push17=, $1, $2 - br_if $pop17, 0 # 0: down to label2 + br_if 0, $pop17 # 0: down to label2 # BB#10: # %for.cond12 i32.load $push18=, bad_t2+4($0) i32.call_indirect $push19=, $pop18, $2 - br_if $pop19, 0 # 0: down to label2 + br_if 0, $pop19 # 0: down to label2 # BB#11: # %for.cond12.1 block i32.load $push20=, good_t0($0) i32.call_indirect $push21=, $pop20 i32.const $push32=, 0 i32.eq $push33=, $pop21, $pop32 - br_if $pop33, 0 # 0: down to label3 + br_if 0, $pop33 # 0: down to label3 # BB#12: # %for.cond23 i32.load $push22=, good_t0+4($0) i32.call_indirect $push23=, $pop22 i32.const $push34=, 0 i32.eq $push35=, $pop23, $pop34 - br_if $pop35, 0 # 0: down to label3 + br_if 0, $pop35 # 0: down to label3 # BB#13: # %for.cond23.1 i32.load $push24=, good_t0+8($0) i32.call_indirect $push25=, $pop24 i32.const $push36=, 0 i32.eq $push37=, $pop25, $pop36 - br_if $pop37, 0 # 0: down to label3 + br_if 0, $pop37 # 0: down to label3 # BB#14: # %for.cond23.2 block i32.load $push26=, opt_t0($0) i32.call_indirect $push27=, $pop26 i32.const $push38=, 0 i32.eq $push39=, $pop27, $pop38 - br_if $pop39, 0 # 0: down to label4 + br_if 0, $pop39 # 0: down to label4 # BB#15: # %for.cond34 i32.load $push28=, opt_t0+4($0) i32.call_indirect $push29=, $pop28 i32.const $push40=, 0 i32.eq $push41=, $pop29, $pop40 - br_if $pop41, 0 # 0: down to label4 + br_if 0, $pop41 # 0: down to label4 # BB#16: # %for.cond34.1 i32.load $push30=, opt_t0+8($0) i32.call_indirect $push31=, $pop30 i32.const $push42=, 0 i32.eq $push43=, $pop31, $pop42 - br_if $pop43, 0 # 0: down to label4 + br_if 0, $pop43 # 0: down to label4 # BB#17: # %for.cond34.2 call exit@FUNCTION, $0 unreachable diff --git a/test/dot_s/memops.s b/test/dot_s/memops.s index aadab0db2..6e4e1ac59 100644 --- a/test/dot_s/memops.s +++ b/test/dot_s/memops.s @@ -46,7 +46,7 @@ main: # @main i32.const $3=, 1048576 i32.ne $push2=, $4, $3 copy_local $5=, $1 - br_if $pop2, 0 + br_if 0, $pop2 end_loop loop i32.const $11=, 0 @@ -57,7 +57,7 @@ main: # @main i32.add $6=, $pop5, $6 i32.add $5=, $5, $2 i32.ne $push6=, $5, $3 - br_if $pop6, 0 + br_if 0, $pop6 end_loop i32.const $push7=, 3 i32.mul $push8=, $6, $pop7 @@ -71,7 +71,7 @@ main: # @main i32.add $0=, $0, $2 i32.const $push15=, 100 i32.ne $push16=, $0, $pop15 - br_if $pop16, 0 + br_if 0, $pop16 end_loop call _Z6reporti@FUNCTION, $6 i32.const $push17=, 0 diff --git a/test/emcc_O2_hello_world.wast.fromBinary b/test/emcc_O2_hello_world.wast.fromBinary index d69d6e577..6ede653f6 100644 --- a/test/emcc_O2_hello_world.wast.fromBinary +++ b/test/emcc_O2_hello_world.wast.fromBinary @@ -4657,12 +4657,11 @@ ) ) ) - (br_if + (br_if $label$165 (i32.ne (get_local $var$62) (i32.const 0) ) - $label$165 ) ) ) @@ -6657,7 +6656,7 @@ (get_local $var$62) (i32.const 7) ) - (br_if + (br_if $label$236 (i32.lt_u (i32.shr_u (i32.add @@ -6671,7 +6670,6 @@ (i32.const 0) ) ) - $label$236 ) ) ) @@ -7355,12 +7353,11 @@ (i32.const 1) ) ) - (br_if + (br_if $label$256 (i32.ne (get_local $var$4) (i32.const 32) ) - $label$256 ) ) ) diff --git a/test/emcc_hello_world.wast.fromBinary b/test/emcc_hello_world.wast.fromBinary index ff26b930f..eaed95225 100644 --- a/test/emcc_hello_world.wast.fromBinary +++ b/test/emcc_hello_world.wast.fromBinary @@ -2448,12 +2448,11 @@ (i32.const 4) ) ) - (br_if + (br_if $label$2 (i32.lt_s (get_local $var$46) (get_local $var$49) ) - $label$2 ) ) ) diff --git a/test/llvm_autogenerated/cfg-stackify.s b/test/llvm_autogenerated/cfg-stackify.s index 9de7ef013..13e69f38c 100644 --- a/test/llvm_autogenerated/cfg-stackify.s +++ b/test/llvm_autogenerated/cfg-stackify.s @@ -11,7 +11,7 @@ test0: i32.const $push1=, 1 i32.add $1=, $1, $pop1 i32.ge_s $push0=, $1, $0 - br_if $pop0, 1 + br_if 1, $pop0 call something@FUNCTION br 0 .LBB0_3: @@ -32,7 +32,7 @@ test1: i32.const $push1=, 1 i32.add $1=, $1, $pop1 i32.ge_s $push0=, $1, $0 - br_if $pop0, 1 + br_if 1, $pop0 call something@FUNCTION br 0 .LBB1_3: @@ -49,7 +49,7 @@ test2: block i32.const $push0=, 1 i32.lt_s $push1=, $1, $pop0 - br_if $pop1, 0 + br_if 0, $pop1 .LBB2_1: loop i32.const $push5=, -1 @@ -60,7 +60,7 @@ test2: f64.store $discard=, 0($0), $pop4 i32.const $push6=, 8 i32.add $0=, $0, $pop6 - br_if $1, 0 + br_if 0, $1 .LBB2_2: end_loop end_block @@ -74,20 +74,20 @@ test2: doublediamond: .param i32, i32, i32 .result i32 - block - block i32.const $push0=, 0 i32.store $discard=, 0($2), $pop0 - br_if $0, 0 + block + block + br_if 0, $0 i32.const $push4=, 1 i32.store $discard=, 0($2), $pop4 br 1 .LBB3_2: end_block - block i32.const $push1=, 2 i32.store $discard=, 0($2), $pop1 - br_if $1, 0 + block + br_if 0, $1 i32.const $push3=, 3 i32.store $discard=, 0($2), $pop3 br 1 @@ -111,10 +111,10 @@ triangle: .param i32, i32 .result i32 .local i32 - block i32.const $push0=, 0 i32.store $2=, 0($0), $pop0 - br_if $1, 0 + block + br_if 0, $1 i32.const $push1=, 1 i32.store $discard=, 0($0), $pop1 .LBB4_2: @@ -131,11 +131,11 @@ triangle: diamond: .param i32, i32 .result i32 - block - block i32.const $push0=, 0 i32.store $discard=, 0($0), $pop0 - br_if $1, 0 + block + block + br_if 0, $1 i32.const $push2=, 1 i32.store $discard=, 0($0), $pop2 br 1 @@ -196,7 +196,7 @@ simple_loop: i32.store $discard=, 0($0), $pop3 i32.const $push4=, 0 i32.eq $push5=, $1, $pop4 - br_if $pop5, 0 + br_if 0, $pop5 end_loop i32.const $push1=, 2 i32.store $discard=, 0($0), $pop1 @@ -212,14 +212,14 @@ doubletriangle: .param i32, i32, i32 .result i32 .local i32 - block i32.const $push0=, 0 i32.store $3=, 0($2), $pop0 - br_if $0, 0 block + br_if 0, $0 i32.const $push1=, 2 i32.store $discard=, 0($2), $pop1 - br_if $1, 0 + block + br_if 0, $1 i32.const $push2=, 3 i32.store $discard=, 0($2), $pop2 .LBB9_3: @@ -240,11 +240,11 @@ doubletriangle: ifelse_earlyexits: .param i32, i32, i32 .result i32 - block - block i32.const $push0=, 0 i32.store $discard=, 0($2), $pop0 - br_if $0, 0 + block + block + br_if 0, $0 i32.const $push3=, 1 i32.store $discard=, 0($2), $pop3 br 1 @@ -252,7 +252,7 @@ ifelse_earlyexits: end_block i32.const $push1=, 2 i32.store $discard=, 0($2), $pop1 - br_if $1, 0 + br_if 0, $1 i32.const $push2=, 3 i32.store $discard=, 0($2), $pop2 .LBB10_4: @@ -272,20 +272,20 @@ doublediamond_in_a_loop: .result i32 .LBB11_1: loop - block - block i32.const $push0=, 0 i32.store $discard=, 0($2), $pop0 - br_if $0, 0 + block + block + br_if 0, $0 i32.const $push1=, 1 i32.store $discard=, 0($2), $pop1 br 1 .LBB11_3: end_block - block i32.const $push2=, 2 i32.store $discard=, 0($2), $pop2 - br_if $1, 0 + block + br_if 0, $1 i32.const $push3=, 3 i32.store $discard=, 0($2), $pop3 br 1 @@ -310,14 +310,14 @@ test3: .param i32 block i32.const $push0=, 0 - br_if $pop0, 0 + br_if 0, $pop0 .LBB12_1: loop - br_if $0, 1 + br_if 1, $0 .LBB12_2: loop i32.ne $push1=, $0, $0 - br_if $pop1, 0 + br_if 0, $pop1 end_loop call bar@FUNCTION br 0 @@ -340,14 +340,14 @@ test4: block i32.const $push0=, 3 i32.gt_s $push1=, $0, $pop0 - br_if $pop1, 0 + br_if 0, $pop1 block i32.const $push8=, 0 i32.eq $push9=, $0, $pop8 - br_if $pop9, 0 + br_if 0, $pop9 i32.const $push6=, 2 i32.ne $push7=, $0, $pop6 - br_if $pop7, 2 + br_if 2, $pop7 .LBB13_3: end_block return @@ -355,10 +355,10 @@ test4: end_block i32.const $push2=, 4 i32.eq $push3=, $0, $pop2 - br_if $pop3, 1 + br_if 1, $pop3 i32.const $push4=, 622 i32.ne $push5=, $0, $pop4 - br_if $pop5, 0 + br_if 0, $pop5 return .LBB13_7: end_block @@ -387,10 +387,10 @@ test5: i32.store $1=, 0($pop7), $pop6 i32.const $push9=, 0 i32.eq $push10=, $0, $pop9 - br_if $pop10, 2 + br_if 2, $pop10 i32.const $push8=, 1 i32.store $discard=, 0($1), $pop8 - br_if $2, 0 + br_if 0, $2 end_loop i32.const $push2=, 0 i32.const $push3=, 3 @@ -422,7 +422,7 @@ test6: i32.store $0=, 0($pop10), $pop9 i32.const $push14=, 0 i32.eq $push15=, $2, $pop14 - br_if $pop15, 3 + br_if 3, $pop15 i32.const $push13=, 1 i32.store $push0=, 0($0), $pop13 tee_local $push12=, $4=, $pop0 @@ -430,9 +430,9 @@ test6: tee_local $push11=, $3=, $pop1 i32.const $push16=, 0 i32.eq $push17=, $pop11, $pop16 - br_if $pop17, 2 + br_if 2, $pop17 i32.store $discard=, 0($0), $4 - br_if $3, 0 + br_if 0, $3 end_loop i32.const $push6=, 0 i32.const $push7=, 2 @@ -465,14 +465,14 @@ test7: i32.and $3=, $0, $pop7 .LBB16_1: loop - block i32.const $push9=, 1 i32.store $0=, 0($2), $pop9 - br_if $3, 0 + block + br_if 0, $3 i32.const $push10=, 2 i32.store $discard=, 0($2), $pop10 i32.and $push1=, $1, $0 - br_if $pop1, 1 + br_if 1, $pop1 i32.const $push2=, 0 i32.const $push3=, 4 i32.store $discard=, 0($pop2), $pop3 @@ -482,7 +482,7 @@ test7: i32.const $push11=, 3 i32.store $discard=, 0($2), $pop11 i32.and $push4=, $1, $0 - br_if $pop4, 0 + br_if 0, $pop4 end_loop i32.const $push5=, 0 i32.const $push6=, 5 @@ -502,16 +502,16 @@ test8: i32.const $push0=, 0 i32.const $push3=, 0 i32.eq $push4=, $pop0, $pop3 - br_if $pop4, 0 + br_if 0, $pop4 i32.const $push2=, 0 i32.const $push5=, 0 i32.eq $push6=, $pop2, $pop5 - br_if $pop6, 1 + br_if 1, $pop6 .LBB17_3: end_block loop i32.const $push1=, 0 - br_if $pop1, 0 + br_if 0, $pop1 br 2 .LBB17_4: end_loop @@ -536,22 +536,22 @@ test9: i32.and $push3=, $pop13, $pop2 i32.const $push18=, 0 i32.eq $push19=, $pop3, $pop18 - br_if $pop19, 1 + br_if 1, $pop19 .LBB18_2: loop - block i32.const $push15=, 2 i32.store $discard=, 0($0), $pop15 + block i32.call $push6=, a@FUNCTION i32.and $push7=, $pop6, $1 i32.const $push20=, 0 i32.eq $push21=, $pop7, $pop20 - br_if $pop21, 0 + br_if 0, $pop21 i32.const $push16=, 3 i32.store $discard=, 0($0), $pop16 i32.call $push10=, a@FUNCTION i32.and $push11=, $pop10, $1 - br_if $pop11, 1 + br_if 1, $pop11 br 3 .LBB18_4: end_block @@ -559,7 +559,7 @@ test9: i32.store $discard=, 0($0), $pop17 i32.call $push8=, a@FUNCTION i32.and $push9=, $pop8, $1 - br_if $pop9, 0 + br_if 0, $pop9 br 2 .LBB18_5: end_loop @@ -584,7 +584,7 @@ test10: i32.const $1=, 0 i32.const $0=, 3 i32.const $2=, 4 - br_if $4, 0 + br_if 0, $4 .LBB19_2: block loop @@ -595,7 +595,7 @@ test10: copy_local $2=, $4 i32.const $push1=, 4 i32.gt_u $push0=, $2, $pop1 - br_if $pop0, 5 + br_if 5, $pop0 copy_local $4=, $3 tableswitch $2, 0, 0, 1, 5, 2, 4 .LBB19_5: @@ -624,16 +624,16 @@ test11: i32.const $push15=, 0 i32.store $push1=, 0($pop0), $pop15 tee_local $push14=, $0=, $pop1 - br_if $pop14, 0 - block + br_if 0, $pop14 i32.const $push7=, 1 i32.store $discard=, 0($0), $pop7 - br_if $0, 0 + block + br_if 0, $0 i32.const $push9=, 0 i32.const $push8=, 2 i32.store $discard=, 0($pop9), $pop8 i32.const $push16=, 0 - br_if $pop16, 2 + br_if 2, $pop16 .LBB20_3: end_block i32.const $push12=, 0 @@ -644,14 +644,14 @@ test11: end_block i32.const $push2=, 4 i32.store $discard=, 0($0), $pop2 - br_if $0, 2 + br_if 2, $0 i32.const $push18=, 0 i32.const $push3=, 5 i32.store $discard=, 0($pop18), $pop3 i32.const $push17=, 0 i32.const $push20=, 0 i32.eq $push21=, $pop17, $pop20 - br_if $pop21, 1 + br_if 1, $pop21 .LBB20_6: end_block i32.const $push10=, 0 @@ -688,22 +688,22 @@ test12: tee_local $push7=, $1=, $pop0 i32.const $push6=, 103 i32.gt_s $push1=, $pop7, $pop6 - br_if $pop1, 0 + br_if 0, $pop1 i32.const $push8=, 42 i32.eq $push4=, $1, $pop8 - br_if $pop4, 2 + br_if 2, $pop4 i32.const $push9=, 76 i32.eq $push5=, $1, $pop9 - br_if $pop5, 2 + br_if 2, $pop5 br 1 .LBB21_4: end_block i32.const $push10=, 108 i32.eq $push2=, $1, $pop10 - br_if $pop2, 1 + br_if 1, $pop2 i32.const $push11=, 104 i32.eq $push3=, $1, $pop11 - br_if $pop3, 1 + br_if 1, $pop3 .LBB21_6: end_block return @@ -724,24 +724,25 @@ test13: .local i32 block i32.const $push0=, 0 - i32.const $push3=, 0 - i32.eq $push4=, $pop0, $pop3 - br_if $pop4, 0 + i32.const $push4=, 0 + i32.eq $push5=, $pop0, $pop4 + br_if 0, $pop5 return .LBB22_2: end_block i32.const $0=, 0 block - br_if $0, 0 + i32.const $push3=, 0 + br_if 0, $pop3 i32.const $0=, 0 .LBB22_4: end_block block i32.const $push1=, 1 i32.and $push2=, $0, $pop1 - i32.const $push5=, 0 - i32.eq $push6=, $pop2, $pop5 - br_if $pop6, 0 + i32.const $push6=, 0 + i32.eq $push7=, $pop2, $pop6 + br_if 0, $pop7 end_block unreachable .endfunc @@ -754,13 +755,13 @@ test14: .LBB23_1: loop i32.const $push0=, 0 - br_if $pop0, 0 + br_if 0, $pop0 .LBB23_2: end_loop loop i32.const $discard=, 0 i32.const $push1=, 0 - br_if $pop1, 0 + br_if 0, $pop1 end_loop return .endfunc diff --git a/test/llvm_autogenerated/cfg-stackify.wast b/test/llvm_autogenerated/cfg-stackify.wast index d801f87c7..b932fd055 100644 --- a/test/llvm_autogenerated/cfg-stackify.wast +++ b/test/llvm_autogenerated/cfg-stackify.wast @@ -113,12 +113,12 @@ (return) ) (func $doublediamond (param $$0 i32) (param $$1 i32) (param $$2 i32) (result i32) + (i32.store align=4 + (get_local $$2) + (i32.const 0) + ) (block $label$0 (block $label$1 - (i32.store align=4 - (get_local $$2) - (i32.const 0) - ) (br_if $label$1 (get_local $$0) ) @@ -128,11 +128,11 @@ ) (br $label$0) ) + (i32.store align=4 + (get_local $$2) + (i32.const 2) + ) (block $label$2 - (i32.store align=4 - (get_local $$2) - (i32.const 2) - ) (br_if $label$2 (get_local $$1) ) @@ -157,13 +157,13 @@ ) (func $triangle (param $$0 i32) (param $$1 i32) (result i32) (local $$2 i32) - (block $label$0 - (set_local $$2 - (i32.store align=4 - (get_local $$0) - (i32.const 0) - ) + (set_local $$2 + (i32.store align=4 + (get_local $$0) + (i32.const 0) ) + ) + (block $label$0 (br_if $label$0 (get_local $$1) ) @@ -181,12 +181,12 @@ ) ) (func $diamond (param $$0 i32) (param $$1 i32) (result i32) + (i32.store align=4 + (get_local $$0) + (i32.const 0) + ) (block $label$0 (block $label$1 - (i32.store align=4 - (get_local $$0) - (i32.const 0) - ) (br_if $label$1 (get_local $$1) ) @@ -257,21 +257,21 @@ ) (func $doubletriangle (param $$0 i32) (param $$1 i32) (param $$2 i32) (result i32) (local $$3 i32) - (block $label$0 - (set_local $$3 - (i32.store align=4 - (get_local $$2) - (i32.const 0) - ) + (set_local $$3 + (i32.store align=4 + (get_local $$2) + (i32.const 0) ) + ) + (block $label$0 (br_if $label$0 (get_local $$0) ) + (i32.store align=4 + (get_local $$2) + (i32.const 2) + ) (block $label$1 - (i32.store align=4 - (get_local $$2) - (i32.const 2) - ) (br_if $label$1 (get_local $$1) ) @@ -294,12 +294,12 @@ ) ) (func $ifelse_earlyexits (param $$0 i32) (param $$1 i32) (param $$2 i32) (result i32) + (i32.store align=4 + (get_local $$2) + (i32.const 0) + ) (block $label$0 (block $label$1 - (i32.store align=4 - (get_local $$2) - (i32.const 0) - ) (br_if $label$1 (get_local $$0) ) @@ -331,12 +331,12 @@ ) (func $doublediamond_in_a_loop (param $$0 i32) (param $$1 i32) (param $$2 i32) (result i32) (loop $label$1 $label$0 + (i32.store align=4 + (get_local $$2) + (i32.const 0) + ) (block $label$2 (block $label$3 - (i32.store align=4 - (get_local $$2) - (i32.const 0) - ) (br_if $label$3 (get_local $$0) ) @@ -346,11 +346,11 @@ ) (br $label$2) ) + (i32.store align=4 + (get_local $$2) + (i32.const 2) + ) (block $label$4 - (i32.store align=4 - (get_local $$2) - (i32.const 2) - ) (br_if $label$4 (get_local $$1) ) @@ -570,13 +570,13 @@ ) ) (loop $label$1 $label$0 - (block $label$2 - (set_local $$0 - (i32.store align=4 - (get_local $$2) - (i32.const 1) - ) + (set_local $$0 + (i32.store align=4 + (get_local $$2) + (i32.const 1) ) + ) + (block $label$2 (br_if $label$2 (get_local $$3) ) @@ -662,11 +662,11 @@ ) ) (loop $label$3 $label$2 + (i32.store align=4 + (get_local $$0) + (i32.const 2) + ) (block $label$4 - (i32.store align=4 - (get_local $$0) - (i32.const 2) - ) (br_if $label$4 (i32.eq (i32.and @@ -784,11 +784,11 @@ ) ) ) + (i32.store align=4 + (get_local $$0) + (i32.const 1) + ) (block $label$4 - (i32.store align=4 - (get_local $$0) - (i32.const 1) - ) (br_if $label$4 (get_local $$0) ) @@ -912,7 +912,7 @@ ) (block $label$1 (br_if $label$1 - (get_local $$0) + (i32.const 0) ) (set_local $$0 (i32.const 0) diff --git a/test/llvm_autogenerated/dead-vreg.s b/test/llvm_autogenerated/dead-vreg.s index 8839c3011..dcc517d05 100644 --- a/test/llvm_autogenerated/dead-vreg.s +++ b/test/llvm_autogenerated/dead-vreg.s @@ -8,7 +8,7 @@ foo: block i32.const $push3=, 1 i32.lt_s $push0=, $2, $pop3 - br_if $pop0, 0 + br_if 0, $pop0 i32.const $push1=, 2 i32.shl $3=, $1, $pop1 i32.const $5=, 0 @@ -20,7 +20,7 @@ foo: copy_local $7=, $0 copy_local $8=, $1 block - br_if $4, 0 + br_if 0, $4 .LBB0_3: loop i32.store $discard=, 0($7), $6 @@ -29,7 +29,7 @@ foo: i32.const $push5=, 4 i32.add $7=, $7, $pop5 i32.add $6=, $6, $5 - br_if $8, 0 + br_if 0, $8 .LBB0_4: end_loop end_block @@ -37,7 +37,7 @@ foo: i32.add $5=, $5, $pop7 i32.add $0=, $0, $3 i32.ne $push2=, $5, $2 - br_if $pop2, 0 + br_if 0, $pop2 .LBB0_5: end_loop end_block diff --git a/test/llvm_autogenerated/func.s b/test/llvm_autogenerated/func.s index fbe92c359..6573e62b2 100644 --- a/test/llvm_autogenerated/func.s +++ b/test/llvm_autogenerated/func.s @@ -48,7 +48,7 @@ f4: i32.and $push0=, $0, $pop2 i32.const $push4=, 0 i32.eq $push5=, $pop0, $pop4 - br_if $pop5, 0 + br_if 0, $pop5 i32.const $push1=, 0 return $pop1 .LBB4_2: diff --git a/test/llvm_autogenerated/legalize.s b/test/llvm_autogenerated/legalize.s index 5ca96894d..584ad6774 100644 --- a/test/llvm_autogenerated/legalize.s +++ b/test/llvm_autogenerated/legalize.s @@ -1,5 +1,5 @@ .text - .file "/s/llvm-upstream/llvm/test/CodeGen/WebAssembly/legalize.ll" + .file "/s/llvm/llvm/test/CodeGen/WebAssembly/legalize.ll" .globl shl_i3 .type shl_i3,@function shl_i3: diff --git a/test/llvm_autogenerated/mem-intrinsics.s b/test/llvm_autogenerated/mem-intrinsics.s index 286d105ad..2f1bc7846 100644 --- a/test/llvm_autogenerated/mem-intrinsics.s +++ b/test/llvm_autogenerated/mem-intrinsics.s @@ -99,12 +99,12 @@ discard_result: block i32.const $push0=, 0 i32.eq $push1=, $3, $pop0 - br_if $pop1, 0 + br_if 0, $pop1 i32.call $0=, def@FUNCTION br 1 .LBB7_2: end_block - br_if $4, 0 + br_if 0, $4 i32.call $discard=, memset@FUNCTION, $0, $1, $2 .LBB7_4: end_block diff --git a/test/llvm_autogenerated/phi.s b/test/llvm_autogenerated/phi.s index 4a3a6d522..81605658c 100644 --- a/test/llvm_autogenerated/phi.s +++ b/test/llvm_autogenerated/phi.s @@ -8,7 +8,7 @@ test0: block i32.const $push0=, -1 i32.gt_s $push1=, $0, $pop0 - br_if $pop1, 0 + br_if 0, $pop1 i32.const $push2=, 3 i32.div_s $0=, $0, $pop2 .LBB0_2: @@ -35,7 +35,7 @@ test1: i32.add $4=, $4, $pop1 copy_local $2=, $1 i32.lt_s $push0=, $4, $0 - br_if $pop0, 0 + br_if 0, $pop0 end_loop return $3 .endfunc diff --git a/test/llvm_autogenerated/reg-stackify.s b/test/llvm_autogenerated/reg-stackify.s index 17ed02ea4..0e5b4f6e4 100644 --- a/test/llvm_autogenerated/reg-stackify.s +++ b/test/llvm_autogenerated/reg-stackify.s @@ -69,7 +69,7 @@ stack_uses: i32.xor $push7=, $pop5, $pop6 i32.const $push10=, 1 i32.ne $push8=, $pop7, $pop10 - br_if $pop8, 0 + br_if 0, $pop8 i32.const $push9=, 0 return $pop9 .LBB4_2: @@ -89,9 +89,9 @@ multiple_uses: i32.load $push0=, 0($2) tee_local $push3=, $3=, $pop0 i32.ge_u $push1=, $pop3, $1 - br_if $pop1, 0 + br_if 0, $pop1 i32.lt_u $push2=, $3, $0 - br_if $pop2, 0 + br_if 0, $pop2 i32.store $discard=, 0($2), $3 .LBB5_3: end_block @@ -180,4 +180,21 @@ commute: .Lfunc_end10: .size commute, .Lfunc_end10-commute + .globl no_stackify_past_use + .type no_stackify_past_use,@function +no_stackify_past_use: + .param i32 + .result i32 + .local i32 + i32.call $1=, callee@FUNCTION, $0 + i32.const $push0=, 1 + i32.add $push1=, $0, $pop0 + i32.call $push2=, callee@FUNCTION, $pop1 + i32.add $push3=, $1, $pop2 + i32.mul $push4=, $1, $pop3 + return $pop4 + .endfunc +.Lfunc_end11: + .size no_stackify_past_use, .Lfunc_end11-no_stackify_past_use + diff --git a/test/llvm_autogenerated/reg-stackify.wast b/test/llvm_autogenerated/reg-stackify.wast index 6acf6d712..1d89a5c73 100644 --- a/test/llvm_autogenerated/reg-stackify.wast +++ b/test/llvm_autogenerated/reg-stackify.wast @@ -4,6 +4,7 @@ (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$i (func (result i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) (import $evoke_side_effects "env" "evoke_side_effects") (import $use_a "env" "use_a" (param i32)) (import $use_b "env" "use_b" (param i32)) @@ -11,6 +12,7 @@ (import $red "env" "red" (result i32)) (import $green "env" "green" (result i32)) (import $blue "env" "blue" (result i32)) + (import $callee "env" "callee" (param i32) (result i32)) (export "no0" $no0) (export "no1" $no1) (export "yes0" $yes0) @@ -22,6 +24,7 @@ (export "simple_multiple_use" $simple_multiple_use) (export "multiple_uses_in_same_insn" $multiple_uses_in_same_insn) (export "commute" $commute) + (export "no_stackify_past_use" $no_stackify_past_use) (func $no0 (param $$0 i32) (param $$1 i32) (result i32) (set_local $$1 (i32.load align=4 @@ -234,5 +237,27 @@ ) ) ) + (func $no_stackify_past_use (param $$0 i32) (result i32) + (local $$1 i32) + (set_local $$1 + (call_import $callee + (get_local $$0) + ) + ) + (return + (i32.mul + (get_local $$1) + (i32.add + (get_local $$1) + (call_import $callee + (i32.add + (get_local $$0) + (i32.const 1) + ) + ) + ) + ) + ) + ) ) ;; METADATA: { "asmConsts": {},"staticBump": 4 } diff --git a/test/llvm_autogenerated/select.s b/test/llvm_autogenerated/select.s index 676dae6df..d85c80649 100644 --- a/test/llvm_autogenerated/select.s +++ b/test/llvm_autogenerated/select.s @@ -1,5 +1,5 @@ .text - .file "/s/llvm-upstream/llvm/test/CodeGen/WebAssembly/select.ll" + .file "/s/llvm/llvm/test/CodeGen/WebAssembly/select.ll" .globl select_i32_bool .type select_i32_bool,@function select_i32_bool: diff --git a/test/llvm_autogenerated/store-results.s b/test/llvm_autogenerated/store-results.s index d590322f4..703f6fb15 100644 --- a/test/llvm_autogenerated/store-results.s +++ b/test/llvm_autogenerated/store-results.s @@ -26,7 +26,7 @@ foo: i32.add $0=, $0, $pop2 i32.const $push1=, 256 i32.ne $push0=, $0, $pop1 - br_if $pop0, 0 + br_if 0, $pop0 end_loop return .endfunc @@ -47,13 +47,36 @@ bar: f32.add $0=, $0, $pop2 f32.const $push1=, 0x1p8 f32.ne $push0=, $0, $pop1 - br_if $pop0, 0 + br_if 0, $pop0 end_loop return .endfunc .Lfunc_end2: .size bar, .Lfunc_end2-bar + .hidden fi_ret + .globl fi_ret + .type fi_ret,@function +fi_ret: + .param i32 + .result i32 + .local i32, i32, i32, i32 + i32.const $1=, __stack_pointer + i32.load $1=, 0($1) + i32.const $2=, 32 + i32.sub $4=, $1, $2 + i32.const $2=, __stack_pointer + i32.store $4=, 0($2), $4 + i32.store $discard=, 0($0), $4 + i32.const $3=, 32 + i32.add $4=, $4, $3 + i32.const $3=, __stack_pointer + i32.store $4=, 0($3), $4 + return $4 + .endfunc +.Lfunc_end3: + .size fi_ret, .Lfunc_end3-fi_ret + .type pos,@object .bss .globl pos diff --git a/test/llvm_autogenerated/store-results.wast b/test/llvm_autogenerated/store-results.wast index 222e66313..401e83723 100644 --- a/test/llvm_autogenerated/store-results.wast +++ b/test/llvm_autogenerated/store-results.wast @@ -3,6 +3,7 @@ (export "single_block" $single_block) (export "foo" $foo) (export "bar" $bar) + (export "fi_ret" $fi_ret) (func $single_block (param $$0 i32) (result i32) (return (i32.store align=4 @@ -61,5 +62,62 @@ ) (return) ) + (func $fi_ret (param $$0 i32) (result i32) + (local $$1 i32) + (local $$2 i32) + (local $$3 i32) + (local $$4 i32) + (set_local $$1 + (i32.const 1) + ) + (set_local $$1 + (i32.load align=4 + (get_local $$1) + ) + ) + (set_local $$2 + (i32.const 32) + ) + (set_local $$4 + (i32.sub + (get_local $$1) + (get_local $$2) + ) + ) + (set_local $$2 + (i32.const 1) + ) + (set_local $$4 + (i32.store align=4 + (get_local $$2) + (get_local $$4) + ) + ) + (i32.store align=4 + (get_local $$0) + (get_local $$4) + ) + (set_local $$3 + (i32.const 32) + ) + (set_local $$4 + (i32.add + (get_local $$4) + (get_local $$3) + ) + ) + (set_local $$3 + (i32.const 1) + ) + (set_local $$4 + (i32.store align=4 + (get_local $$3) + (get_local $$4) + ) + ) + (return + (get_local $$4) + ) + ) ) ;; METADATA: { "asmConsts": {},"staticBump": 19 } diff --git a/test/llvm_autogenerated/switch.s b/test/llvm_autogenerated/switch.s index 24438e83b..16a06486a 100644 --- a/test/llvm_autogenerated/switch.s +++ b/test/llvm_autogenerated/switch.s @@ -7,7 +7,7 @@ bar32: block i32.const $push0=, 23 i32.gt_u $push1=, $0, $pop0 - br_if $pop1, 0 + br_if 0, $pop1 block block block @@ -52,7 +52,7 @@ bar64: block i64.const $push1=, 23 i64.gt_u $push2=, $0, $pop1 - br_if $pop2, 0 + br_if 0, $pop2 block block block diff --git a/test/llvm_autogenerated/userstack.s b/test/llvm_autogenerated/userstack.s index ede7be4f7..f7e1853b5 100644 --- a/test/llvm_autogenerated/userstack.s +++ b/test/llvm_autogenerated/userstack.s @@ -73,21 +73,25 @@ allocarray: .globl non_mem_use .type non_mem_use,@function non_mem_use: - .local i32, i32, i32, i32, i32 - i32.const $0=, __stack_pointer - i32.load $0=, 0($0) - i32.const $1=, 16 - i32.sub $4=, $0, $1 + .param i32 + .local i32, i32, i32, i32, i32, i32 i32.const $1=, __stack_pointer - i32.store $4=, 0($1), $4 - i32.const $3=, 8 - i32.add $3=, $4, $3 - call ext_func@FUNCTION, $3 - call ext_func@FUNCTION, $4 - i32.const $2=, 16 - i32.add $4=, $4, $2 + i32.load $1=, 0($1) + i32.const $2=, 48 + i32.sub $6=, $1, $2 i32.const $2=, __stack_pointer - i32.store $4=, 0($2), $4 + i32.store $6=, 0($2), $6 + i32.const $4=, 8 + i32.add $4=, $6, $4 + call ext_func@FUNCTION, $4 + call ext_func@FUNCTION, $6 + i32.const $5=, 16 + i32.add $5=, $6, $5 + i32.store $discard=, 0($0), $5 + i32.const $3=, 48 + i32.add $6=, $6, $3 + i32.const $3=, __stack_pointer + i32.store $6=, 0($3), $6 return .endfunc .Lfunc_end3: @@ -119,9 +123,56 @@ allocarray_inbounds: .type dynamic_alloca,@function dynamic_alloca: .param i32 + .local i32, i32, i32, i32 + i32.const $1=, __stack_pointer + i32.load $3=, 0($1) + copy_local $4=, $3 + i32.const $push0=, 2 + i32.shl $push1=, $0, $pop0 + i32.const $push2=, 15 + i32.add $push3=, $pop1, $pop2 + i32.const $push4=, -16 + i32.and $push5=, $pop3, $pop4 + i32.sub $0=, $3, $pop5 + copy_local $3=, $0 + i32.const $push6=, 0 + i32.store $discard=, 0($0), $pop6 + i32.const $2=, __stack_pointer + i32.store $3=, 0($2), $4 return .endfunc .Lfunc_end5: .size dynamic_alloca, .Lfunc_end5-dynamic_alloca + .globl dynamic_static_alloca + .type dynamic_static_alloca,@function +dynamic_static_alloca: + .param i32 + .local i32, i32, i32, i32, i32 + i32.const $1=, __stack_pointer + i32.load $1=, 0($1) + i32.const $2=, 16 + i32.sub $4=, $1, $2 + copy_local $5=, $4 + i32.const $2=, __stack_pointer + i32.store $4=, 0($2), $4 + i32.const $push0=, 2 + i32.shl $push1=, $0, $pop0 + i32.const $push2=, 15 + i32.add $push3=, $pop1, $pop2 + i32.const $push4=, -16 + i32.and $push5=, $pop3, $pop4 + i32.sub $0=, $4, $pop5 + copy_local $4=, $0 + i32.const $push6=, 0 + i32.store $discard=, 0($0), $pop6 + i32.const $3=, 16 + i32.add $4=, $5, $3 + i32.const $3=, __stack_pointer + i32.store $4=, 0($3), $4 + return + .endfunc +.Lfunc_end6: + .size dynamic_static_alloca, .Lfunc_end6-dynamic_static_alloca + diff --git a/test/llvm_autogenerated/userstack.wast b/test/llvm_autogenerated/userstack.wast index 1cbcb4c73..87eb5734f 100644 --- a/test/llvm_autogenerated/userstack.wast +++ b/test/llvm_autogenerated/userstack.wast @@ -8,6 +8,7 @@ (export "non_mem_use" $non_mem_use) (export "allocarray_inbounds" $allocarray_inbounds) (export "dynamic_alloca" $dynamic_alloca) + (export "dynamic_static_alloca" $dynamic_static_alloca) (func $alloca32 (local $$0 i32) (local $$1 i32) @@ -193,69 +194,83 @@ ) (return) ) - (func $non_mem_use - (local $$0 i32) + (func $non_mem_use (param $$0 i32) (local $$1 i32) (local $$2 i32) (local $$3 i32) (local $$4 i32) - (set_local $$0 + (local $$5 i32) + (local $$6 i32) + (set_local $$1 (i32.const 1) ) - (set_local $$0 + (set_local $$1 (i32.load align=4 - (get_local $$0) + (get_local $$1) ) ) - (set_local $$1 - (i32.const 16) + (set_local $$2 + (i32.const 48) ) - (set_local $$4 + (set_local $$6 (i32.sub - (get_local $$0) (get_local $$1) + (get_local $$2) ) ) - (set_local $$1 + (set_local $$2 (i32.const 1) ) - (set_local $$4 + (set_local $$6 (i32.store align=4 - (get_local $$1) - (get_local $$4) + (get_local $$2) + (get_local $$6) ) ) - (set_local $$3 + (set_local $$4 (i32.const 8) ) - (set_local $$3 + (set_local $$4 (i32.add + (get_local $$6) (get_local $$4) - (get_local $$3) ) ) (call_import $ext_func - (get_local $$3) + (get_local $$4) ) (call_import $ext_func - (get_local $$4) + (get_local $$6) ) - (set_local $$2 + (set_local $$5 (i32.const 16) ) - (set_local $$4 + (set_local $$5 (i32.add - (get_local $$4) - (get_local $$2) + (get_local $$6) + (get_local $$5) ) ) - (set_local $$2 + (i32.store align=4 + (get_local $$0) + (get_local $$5) + ) + (set_local $$3 + (i32.const 48) + ) + (set_local $$6 + (i32.add + (get_local $$6) + (get_local $$3) + ) + ) + (set_local $$3 (i32.const 1) ) - (set_local $$4 + (set_local $$6 (i32.store align=4 - (get_local $$2) - (get_local $$4) + (get_local $$3) + (get_local $$6) ) ) (return) @@ -319,6 +334,129 @@ (return) ) (func $dynamic_alloca (param $$0 i32) + (local $$1 i32) + (local $$2 i32) + (local $$3 i32) + (local $$4 i32) + (set_local $$1 + (i32.const 1) + ) + (set_local $$3 + (i32.load align=4 + (get_local $$1) + ) + ) + (set_local $$4 + (get_local $$3) + ) + (set_local $$0 + (i32.sub + (get_local $$3) + (i32.and + (i32.add + (i32.shl + (get_local $$0) + (i32.const 2) + ) + (i32.const 15) + ) + (i32.const -16) + ) + ) + ) + (set_local $$3 + (get_local $$0) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 0) + ) + (set_local $$2 + (i32.const 1) + ) + (set_local $$3 + (i32.store align=4 + (get_local $$2) + (get_local $$4) + ) + ) + (return) + ) + (func $dynamic_static_alloca (param $$0 i32) + (local $$1 i32) + (local $$2 i32) + (local $$3 i32) + (local $$4 i32) + (local $$5 i32) + (set_local $$1 + (i32.const 1) + ) + (set_local $$1 + (i32.load align=4 + (get_local $$1) + ) + ) + (set_local $$2 + (i32.const 16) + ) + (set_local $$4 + (i32.sub + (get_local $$1) + (get_local $$2) + ) + ) + (set_local $$5 + (get_local $$4) + ) + (set_local $$2 + (i32.const 1) + ) + (set_local $$4 + (i32.store align=4 + (get_local $$2) + (get_local $$4) + ) + ) + (set_local $$0 + (i32.sub + (get_local $$4) + (i32.and + (i32.add + (i32.shl + (get_local $$0) + (i32.const 2) + ) + (i32.const 15) + ) + (i32.const -16) + ) + ) + ) + (set_local $$4 + (get_local $$0) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 0) + ) + (set_local $$3 + (i32.const 16) + ) + (set_local $$4 + (i32.add + (get_local $$5) + (get_local $$3) + ) + ) + (set_local $$3 + (i32.const 1) + ) + (set_local $$4 + (i32.store align=4 + (get_local $$3) + (get_local $$4) + ) + ) (return) ) ) |