diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-07-20 10:36:40 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-07-20 11:40:47 -0700 |
commit | 97ad14b01a9fccf1c52e79468b7983c16e0693a8 (patch) | |
tree | 4505e7e4464e3f834a2fb2271bbd3db0799f7973 | |
parent | b5642384c47ddb33187868e1d4cfc002797b2111 (diff) | |
download | binaryen-97ad14b01a9fccf1c52e79468b7983c16e0693a8.tar.gz binaryen-97ad14b01a9fccf1c52e79468b7983c16e0693a8.tar.bz2 binaryen-97ad14b01a9fccf1c52e79468b7983c16e0693a8.zip |
avoid label variable usage in relooper for forward branches, just use a stack of blocks for them. after this change, only irreducible control flow should cause label variable usage
-rw-r--r-- | src/cfg/Relooper.cpp | 125 | ||||
-rw-r--r-- | src/cfg/Relooper.h | 50 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 980 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt.txt | 490 | ||||
-rw-r--r-- | test/example/relooper-fuzz.txt | 64 | ||||
-rw-r--r-- | test/example/relooper-fuzz1.txt | 284 |
6 files changed, 962 insertions, 1031 deletions
diff --git a/src/cfg/Relooper.cpp b/src/cfg/Relooper.cpp index 6488b3d06..cde61df0b 100644 --- a/src/cfg/Relooper.cpp +++ b/src/cfg/Relooper.cpp @@ -18,6 +18,7 @@ #include <string.h> #include <stdlib.h> + #include <list> #include <stack> #include <string> @@ -38,6 +39,59 @@ static void PrintDebug(const char *Format, ...); #define DebugDump(x, ...) #endif +// Rendering utilities + +static wasm::Expression* HandleFollowupMultiples(wasm::Expression* Ret, Shape* Parent, RelooperBuilder& Builder, bool InLoop) { + if (!Parent->Next) return Ret; + + auto* Curr = Ret->dynCast<wasm::Block>(); + if (!Curr || Curr->name.is()) { + Curr = Builder.makeBlock(Ret); + } + // for each multiple after us, we create a block target for breaks to reach + while (Parent->Next) { + auto* Multiple = Shape::IsMultiple(Parent->Next); + if (!Multiple) break; + for (auto& iter : Multiple->InnerMap) { + int Id = iter.first; + Shape* Body = iter.second; + Curr->name = Builder.getBlockBreakName(Id); + auto* Outer = Builder.makeBlock(Curr); + Outer->list.push_back(Body->Render(Builder, InLoop)); + Outer->finalize(); // TODO: not really necessary + Curr = Outer; + } + Parent->Next = Parent->Next->Next; + } + // after the multiples is a simple or a loop, in both cases we must hit an entry + // block, and so this is the last one we need to take into account now (this + // is why we require that loops hit an entry). + if (Parent->Next) { + auto* Simple = Shape::IsSimple(Parent->Next); + if (Simple) { + // breaking on the next block's id takes us out, where we + // will reach its rendering + Curr->name = Builder.getBlockBreakName(Simple->Inner->Id); + } else { + // add one break target per entry for the loop + auto* Loop = Shape::IsLoop(Parent->Next); + assert(Loop); + assert(Loop->Entries.size() > 0); + if (Loop->Entries.size() == 1) { + Curr->name = Builder.getBlockBreakName((*Loop->Entries.begin())->Id); + } else { + for (auto* Entry : Loop->Entries) { + Curr->name = Builder.getBlockBreakName(Entry->Id); + auto* Outer = Builder.makeBlock(Curr); + Outer->finalize(); // TODO: not really necessary + Curr = Outer; + } + } + } + } + return Curr; +} + // Branch Branch::Branch(wasm::Expression* ConditionInit, wasm::Expression* CodeInit) : Ancestor(nullptr), Condition(ConditionInit), Code(CodeInit) {} @@ -53,12 +107,11 @@ wasm::Expression* Branch::Render(RelooperBuilder& Builder, Block *Target, bool S auto* Ret = Builder.makeBlock(); if (Code) Ret->list.push_back(Code); if (SetLabel) Ret->list.push_back(Builder.makeSetLabel(Target->Id)); - if (Ancestor) { - if (Type == Break) { - Ret->list.push_back(Builder.makeShapeBreak(Ancestor->Id)); - } else if (Type == Continue) { - Ret->list.push_back(Builder.makeShapeContinue(Ancestor->Id)); - } + if (Type == Break) { + Ret->list.push_back(Builder.makeBlockBreak(Target->Id)); + } else if (Type == Continue) { + assert(Ancestor); + Ret->list.push_back(Builder.makeShapeContinue(Ancestor->Id)); } Ret->finalize(); return Ret; @@ -128,7 +181,6 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) { if (Fused) { PrintDebug("Fusing Multiple to Simple\n", 0); Parent->Next = Parent->Next->Next; - // When the Multiple has the same number of groups as we have branches, // they will all be fused, so it is safe to not set the label at all. // If a switch, then we can have multiple branches to the same target @@ -171,22 +223,21 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) { } bool SetCurrLabel = SetLabel && Target->IsCheckedMultipleEntry; bool HasFusedContent = Fused && contains(Fused->InnerMap, Target->Id); + if (HasFusedContent) { + assert(Details->Type == Branch::Break); + Details->Type = Branch::Direct; + } wasm::Expression* CurrContent = nullptr; + bool IsDefault = iter == ProcessedBranchesOut.end(); if (SetCurrLabel || Details->Type != Branch::Direct || HasFusedContent || Details->Code) { CurrContent = Details->Render(Builder, Target, SetCurrLabel); if (HasFusedContent) { CurrContent = Builder.blockify(CurrContent, Fused->InnerMap.find(Target->Id)->second->Render(Builder, InLoop)); - } else if (Details->Type == Branch::Nested) { - // Nest the parent content here, and remove it from showing up afterwards as Next - assert(Parent->Next); - CurrContent = Builder.blockify(CurrContent, Parent->Next->Render(Builder, InLoop)); - Parent->Next = nullptr; } } - bool isDefault = iter == ProcessedBranchesOut.end(); // If there is nothing to show in this branch, omit the condition if (CurrContent) { - if (isDefault) { + if (IsDefault) { wasm::Expression* Now; if (RemainingConditions) { Now = Builder.makeIf(RemainingConditions, CurrContent); @@ -217,7 +268,7 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) { RemainingConditions = Now; } } - if (isDefault) break; + if (IsDefault) break; } } else { // Emit a switch @@ -240,16 +291,15 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) { // generate the content for this block bool SetCurrLabel = SetLabel && Target->IsCheckedMultipleEntry; bool HasFusedContent = Fused && contains(Fused->InnerMap, Target->Id); + if (HasFusedContent) { + assert(Details->Type == Branch::Break); + Details->Type = Branch::Direct; + } wasm::Expression* CurrContent = nullptr; if (SetCurrLabel || Details->Type != Branch::Direct || HasFusedContent || Details->Code) { CurrContent = Details->Render(Builder, Target, SetCurrLabel); if (HasFusedContent) { CurrContent = Builder.blockify(CurrContent, Fused->InnerMap.find(Target->Id)->second->Render(Builder, InLoop)); - } else if (Details->Type == Branch::Nested) { - // Nest the parent content here, and remove it from showing up afterwards as Next - assert(Parent->Next); - CurrContent = Builder.blockify(CurrContent, Parent->Next->Render(Builder, InLoop)); - Parent->Next = nullptr; } } // generate a block to branch to, if we have content @@ -285,15 +335,8 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) { } if (Root) { - if (Fused) { - // We are fusing a multiple into this simple - auto* Block = Builder.makeBlock(Root); - Block->name = Builder.getBreakName(Fused->Id); - Root = Block; - } Ret->list.push_back(Root); } - Ret->finalize(); return Ret; @@ -303,6 +346,7 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) { wasm::Expression* SimpleShape::Render(RelooperBuilder& Builder, bool InLoop) { auto* Ret = Inner->Render(Builder, InLoop); + Ret = HandleFollowupMultiples(Ret, this, Builder, InLoop); if (Next) { Ret = Builder.makeSequence(Ret, Next->Render(Builder, InLoop)); } @@ -328,8 +372,8 @@ wasm::Expression* MultipleShape::Render(RelooperBuilder& Builder, bool InLoop) { CurrIf = Now; } } - auto* Ret = Builder.makeBlock(FirstIf); - Ret->name = Builder.getBreakName(Id); + wasm::Expression* Ret = Builder.makeBlock(FirstIf); + Ret = HandleFollowupMultiples(Ret, this, Builder, InLoop); if (Next) { Ret = Builder.makeSequence(Ret, Next->Render(Builder, InLoop)); } @@ -339,7 +383,8 @@ wasm::Expression* MultipleShape::Render(RelooperBuilder& Builder, bool InLoop) { // LoopShape wasm::Expression* LoopShape::Render(RelooperBuilder& Builder, bool InLoop) { - wasm::Expression* Ret = Builder.makeLoop(Builder.getBreakName(Id), Builder.getContinueName(Id), Inner->Render(Builder, true)); + wasm::Expression* Ret = Builder.makeLoop(wasm::Name(), Builder.getShapeContinueName(Id), Inner->Render(Builder, true)); + Ret = HandleFollowupMultiples(Ret, this, Builder, InLoop); if (Next) { Ret = Builder.makeSequence(Ret, Next->Render(Builder, InLoop)); } @@ -455,7 +500,7 @@ void Relooper::Calculate(Block *Entry) { BlockSet JustInner; JustInner.insert(Inner); for (BlockSet::iterator iter = NextEntries.begin(); iter != NextEntries.end(); iter++) { - Solipsize(*iter, Branch::Direct, Simple, JustInner); + Solipsize(*iter, Branch::Break, Simple, JustInner); } } return Simple; @@ -570,6 +615,7 @@ void Relooper::Calculate(Block *Entry) { // Finish up Shape *Inner = Process(InnerBlocks, Entries); Loop->Inner = Inner; + Loop->Entries = Entries; return Loop; } @@ -790,7 +836,8 @@ void Relooper::Calculate(Block *Entry) { if (IndependentGroups.size() > 0) { // We can handle a group in a multiple if its entry cannot be reached by another group. // Note that it might be reachable by itself - a loop. But that is fine, we will create - // a loop inside the multiple block (which is the performant order to do it). + // a loop inside the multiple block, which is both the performant order to do it, and + // preserves the property that a loop will always reach an entry. for (BlockBlockSetMap::iterator iter = IndependentGroups.begin(); iter != IndependentGroups.end();) { Block *Entry = iter->first; BlockSet &Group = iter->second; @@ -853,8 +900,18 @@ void Relooper::Calculate(Block *Entry) { if (IndependentGroups.size() > 0) { // Some groups removable ==> Multiple - // checked multiple if prev is not simple (in which case we would be fused) - Make(MakeMultiple(Blocks, *Entries, IndependentGroups, *NextEntries, !(Shape::IsSimple(Prev)))); + // This is a checked multiple if it has an entry that is an entry to this Process call, that is, + // if we can reach it from outside this set of blocks, then we must check the label variable + // to do so. Otherwise, if it is just internal blocks, those can always be jumped to forward, + // without using the label variable + bool Checked = false; + for (auto* Entry : *Entries) { + if (InitialEntries.count(Entry)) { + Checked = true; + break; + } + } + Make(MakeMultiple(Blocks, *Entries, IndependentGroups, *NextEntries, Checked)); } } // No independent groups, must be loopable ==> Loop diff --git a/src/cfg/Relooper.h b/src/cfg/Relooper.h index 8ac877d08..50f40fd88 100644 --- a/src/cfg/Relooper.h +++ b/src/cfg/Relooper.h @@ -53,17 +53,21 @@ public: wasm::Binary* makeCheckLabel(wasm::Index value) { return makeBinary(wasm::EqInt32, makeGetLabel(), makeConst(wasm::Literal(int32_t(value)))); } - wasm::Break* makeShapeBreak(int id) { - return wasm::Builder::makeBreak(getBreakName(id)); + + // breaks are on blocks, as they can be specific, we make one wasm block per basic block + wasm::Break* makeBlockBreak(int id) { + return wasm::Builder::makeBreak(getBlockBreakName(id)); } + // continues are on shapes, as there is one per loop, and if we have more than one + // going there, it is irreducible control flow anyhow wasm::Break* makeShapeContinue(int id) { - return wasm::Builder::makeBreak(getContinueName(id)); + return wasm::Builder::makeBreak(getShapeContinueName(id)); } - wasm::Name getBreakName(int id) { - return wasm::Name(std::string("shape$") + std::to_string(id) + "$break"); + wasm::Name getBlockBreakName(int id) { + return wasm::Name(std::string("block$") + std::to_string(id) + "$break"); } - wasm::Name getContinueName(int id) { + wasm::Name getShapeContinueName(int id) { return wasm::Name(std::string("shape$") + std::to_string(id) + "$continue"); } }; @@ -76,9 +80,7 @@ struct Branch { enum FlowType { Direct = 0, // We will directly reach the right location through other means, no need for continue or break Break = 1, - Continue = 2, - Nested = 3 // This code is directly reached, but we must be careful to ensure it is nested in an if - it is not reached - // unconditionally, other code paths exist alongside it that we need to make sure do not intertwine + Continue = 2 }; Shape *Ancestor; // If not NULL, this shape is the relevant one for purposes of getting to the target block. We break or continue on it Branch::FlowType Type; // If Ancestor is not NULL, this says whether to break or continue @@ -144,12 +146,14 @@ struct InsertOrderedSet InsertOrderedSet() {} InsertOrderedSet(const InsertOrderedSet& other) { + *this = other; + } + InsertOrderedSet& operator=(const InsertOrderedSet& other) { + clear(); for (auto i : other.List) { insert(i); // inserting manually creates proper iterators } - } - InsertOrderedSet& operator=(const InsertOrderedSet& other) { - abort(); // TODO, watch out for iterators + return *this; } }; @@ -241,15 +245,20 @@ struct Block { // Represents a structured control flow shape, one of // -// Simple: No control flow at all, just instructions. If several -// blocks, then +// Simple: No control flow at all, just instructions in a single +// basic block. // -// Multiple: A shape with more than one entry. If the next block to -// be entered is among them, we run it and continue to -// the next shape, otherwise we continue immediately to the -// next shape. +// Multiple: A shape with at least one entry. We may visit one of +// the entries, or none, before continuing to the next +// shape after this. // -// Loop: An infinite loop. +// Loop: An infinite loop. We assume the property that a loop +// will always visit one of its entries, and so for example +// we cannot have a loop containing a multiple and nothing +// else (since we might not visit any of the multiple's +// blocks). Multiple entries are possible for the block, +// however, which is necessary for irreducible control +// flow, of course. // struct SimpleShape; @@ -285,7 +294,6 @@ struct SimpleShape : public Shape { wasm::Expression* Render(RelooperBuilder& Builder, bool InLoop) override; }; -// Blocks with the same id were split and are identical, so we just care about ids in Multiple entries typedef std::map<int, Shape*> IdShapeMap; struct MultipleShape : public Shape { @@ -299,6 +307,8 @@ struct MultipleShape : public Shape { struct LoopShape : public Shape { Shape *Inner; + BlockSet Entries; // we must visit at least one of these + LoopShape() : Shape(Loop), Inner(NULL) {} wasm::Expression* Render(RelooperBuilder& Builder, bool InLoop) override; }; diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index e541b1704..0d27fa464 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -381,10 +381,13 @@ raw: ) (func $two-blocks (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) + (block + (br $block$2$break) + ) ) (block (call_import $check @@ -394,12 +397,13 @@ raw: ) (func $two-blocks-plus-code (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 77) + (br $block$2$break) ) ) (block @@ -410,11 +414,14 @@ raw: ) (func $loop (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block + (loop $shape$0$continue + (block $block$2$break (call_import $check (i32.const 0) ) + (block + (br $block$2$break) + ) ) (block (call_import $check @@ -428,13 +435,14 @@ raw: ) (func $loop-plus-code (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block + (loop $shape$0$continue + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 33) + (br $block$2$break) ) ) (block @@ -453,18 +461,16 @@ raw: (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) - (block - (call_import $check - (i32.const 1) - ) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) ) - (block - (call_import $check - (i32.const 2) - ) + ) + (block + (call_import $check + (i32.const 2) ) ) ) @@ -474,23 +480,21 @@ raw: (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (i32.const 10) (block - (i32.const 10) - (block - (call_import $check - (i32.const 1) - ) + (call_import $check + (i32.const 1) ) ) + ) + (block + (i32.const 20) (block - (i32.const 20) - (block - (call_import $check - (i32.const 2) - ) + (call_import $check + (i32.const 2) ) ) ) @@ -498,22 +502,21 @@ raw: ) (func $if (type $v) (local $0 i32) - (block + (block $block$3$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (br $shape$1$break) - ) + (br $block$3$break) ) ) + (br $block$3$break) ) ) (block @@ -524,26 +527,27 @@ raw: ) (func $if-plus-code (type $v) (local $0 i32) - (block + (block $block$3$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (i32.const -1) (block - (i32.const -1) + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (i32.const -3) - (br $shape$1$break) - ) + (i32.const -3) + (br $block$3$break) ) ) + ) + (block (i32.const -2) + (br $block$3$break) ) ) ) @@ -555,28 +559,26 @@ raw: ) (func $if-else (type $v) (local $0 i32) - (block + (block $block$4$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (br $shape$1$break) - ) + (br $block$4$break) + ) + ) + (block + (call_import $check + (i32.const 2) ) (block - (call_import $check - (i32.const 2) - ) - (block - (br $shape$1$break) - ) + (br $block$4$break) ) ) ) @@ -589,20 +591,25 @@ raw: ) (func $loop-tail (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block - (call_import $check - (i32.const 0) - ) - ) - (block - (call_import $check - (i32.const 1) + (block $block$3$break + (loop $shape$0$continue + (block $block$2$break + (call_import $check + (i32.const 0) + ) + (block + (br $block$2$break) + ) ) - (if - (i32.const 10) - (br $shape$0$continue) - (br $shape$0$break) + (block + (call_import $check + (i32.const 1) + ) + (if + (i32.const 10) + (br $shape$0$continue) + (br $block$3$break) + ) ) ) ) @@ -614,93 +621,81 @@ raw: ) (func $nontrivial-loop-plus-phi-to-head (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 10) + (br $block$2$break) ) ) (block - (loop $shape$1$break $shape$1$continue - (block - (call_import $check - (i32.const 1) - ) - (if - (i32.eqz - (i32.const -2) - ) - (block - (i32.const 20) - (br $shape$1$break) - ) - ) - ) - (block - (call_import $check - (i32.const 2) - ) - (if - (i32.const -6) - (block - (set_local $0 - (i32.const 4) + (block $block$7$break + (block $block$4$break + (loop $shape$1$continue + (block $block$3$break + (call_import $check + (i32.const 1) + ) + (if + (i32.const -2) + (br $block$3$break) + (block + (i32.const 20) + (br $block$7$break) + ) ) - (br $shape$1$break) ) (block - (i32.const 30) - (br $shape$1$continue) + (call_import $check + (i32.const 2) + ) + (if + (i32.const -6) + (br $block$4$break) + (block + (i32.const 30) + (br $shape$1$continue) + ) + ) ) ) ) - ) - (block - (block $shape$4$break - (if - (i32.eq - (get_local $0) - (i32.const 4) + (block + (block $block$6$break + (call_import $check + (i32.const 3) ) - (block + (if + (i32.const -10) (block (call_import $check - (i32.const 3) - ) - (block $shape$6$break - (if - (i32.const -10) - (block - (call_import $check - (i32.const 4) - ) - (block - (br $shape$6$break) - ) - ) - ) - ) - ) - (block - (call_import $check - (i32.const 5) + (i32.const 4) ) (block - (i32.const 40) - (br $shape$4$break) + (br $block$6$break) ) ) + (br $block$6$break) ) ) - ) - (block - (call_import $check - (i32.const 6) + (block + (call_import $check + (i32.const 5) + ) + (block + (i32.const 40) + (br $block$7$break) + ) ) ) ) + (block + (call_import $check + (i32.const 6) + ) + ) ) ) (func $switch (type $v) @@ -708,43 +703,41 @@ raw: (call_import $check (i32.const 0) ) - (block $shape$1$break - (block $switch$1$leave - (block $switch$1$default - (block $switch$1$case$3 - (block $switch$1$case$2 - (br_table $switch$1$default $switch$1$default $switch$1$case$2 $switch$1$default $switch$1$case$3 $switch$1$case$2 $switch$1$default - (i32.const -99) - ) - ) - (block - (block - (call_import $check - (i32.const 1) - ) - ) + (block $switch$1$leave + (block $switch$1$default + (block $switch$1$case$3 + (block $switch$1$case$2 + (br_table $switch$1$default $switch$1$default $switch$1$case$2 $switch$1$default $switch$1$case$3 $switch$1$case$2 $switch$1$default + (i32.const -99) ) - (br $switch$1$leave) ) (block - (i32.const 55) (block (call_import $check - (i32.const 2) + (i32.const 1) ) ) ) (br $switch$1$leave) ) (block + (i32.const 55) (block (call_import $check - (i32.const 3) + (i32.const 2) ) ) ) (br $switch$1$leave) ) + (block + (block + (call_import $check + (i32.const 3) + ) + ) + ) + (br $switch$1$leave) ) ) (func $duffs-device (type $v) @@ -756,58 +749,66 @@ raw: (local $5 f64) (local $6 i32) (block - (call_import $check - (i32.const 0) + (block $block$3$break + (block $block$2$break + (call_import $check + (i32.const 0) + ) + (if + (i32.const 10) + (block + (set_local $3 + (i32.const 2) + ) + (br $block$2$break) + ) + (block + (set_local $3 + (i32.const 3) + ) + (br $block$3$break) + ) + ) + ) ) + ) + (loop $shape$1$continue (if - (i32.const 10) - (set_local $3 + (i32.eq + (get_local $3) (i32.const 2) ) - (set_local $3 - (i32.const 3) + (block + (set_local $3 + (i32.const 0) + ) + (call_import $check + (i32.const 1) + ) + (block + (set_local $3 + (i32.const 3) + ) + (br $shape$1$continue) + ) ) - ) - ) - (loop $shape$1$break $shape$1$continue - (block $shape$2$break (if (i32.eq (get_local $3) - (i32.const 2) + (i32.const 3) ) (block (set_local $3 (i32.const 0) ) (call_import $check - (i32.const 1) - ) - (block - (set_local $3 - (i32.const 3) - ) - (br $shape$1$continue) - ) - ) - (if - (i32.eq - (get_local $3) - (i32.const 3) + (i32.const 2) ) (block (set_local $3 - (i32.const 0) - ) - (call_import $check (i32.const 2) ) - (block - (set_local $3 - (i32.const 2) - ) - (br $shape$1$continue) - ) + (br $shape$1$continue) ) ) ) @@ -847,7 +848,7 @@ optimized: ) ) (func $loop (type $v) - (loop $shape$0$break $shape$0$continue + (loop $shape$0$continue (call_import $check (i32.const 0) ) @@ -885,21 +886,6 @@ optimized: (i32.const 2) ) ) - (func $if-plus-code (type $v) - (call_import $check - (i32.const 0) - ) - (if - (i32.const 55) - (call_import $check - (i32.const 1) - ) - (i32.const -2) - ) - (call_import $check - (i32.const 2) - ) - ) (func $if-else (type $v) (call_import $check (i32.const 0) @@ -918,17 +904,19 @@ optimized: ) ) (func $loop-tail (type $v) - (loop $shape$0$break $shape$0$continue - (call_import $check - (i32.const 0) - ) - (call_import $check - (i32.const 1) - ) - (if - (i32.const 10) - (br $shape$0$continue) - (br $shape$0$break) + (block $block$3$break + (loop $shape$0$continue + (call_import $check + (i32.const 0) + ) + (call_import $check + (i32.const 1) + ) + (if + (i32.const 10) + (br $shape$0$continue) + (br $block$3$break) + ) ) ) (call_import $check @@ -936,50 +924,40 @@ optimized: ) ) (func $nontrivial-loop-plus-phi-to-head (type $v) - (local $0 i32) (call_import $check (i32.const 0) ) - (loop $shape$1$break $shape$1$continue - (call_import $check - (i32.const 1) - ) - (br_if $shape$1$break - (i32.const 0) - ) - (call_import $check - (i32.const 2) - ) - (if - (i32.const -6) - (block - (set_local $0 - (i32.const 4) + (block $block$7$break + (block $block$4$break + (loop $shape$1$continue + (call_import $check + (i32.const 1) + ) + (br_if $block$7$break + (i32.const 0) ) - (br $shape$1$break) - ) - (br $shape$1$continue) - ) - ) - (if - (i32.eq - (get_local $0) - (i32.const 4) - ) - (block - (call_import $check - (i32.const 3) - ) - (if - (i32.const -10) (call_import $check - (i32.const 4) + (i32.const 2) + ) + (if + (i32.const -6) + (br $block$4$break) + (br $shape$1$continue) ) ) + ) + (call_import $check + (i32.const 3) + ) + (if + (i32.const -10) (call_import $check - (i32.const 5) + (i32.const 4) ) ) + (call_import $check + (i32.const 5) + ) ) (call_import $check (i32.const 6) @@ -1020,7 +998,7 @@ optimized: (set_local $0 (i32.const 2) ) - (loop $shape$1$break $shape$1$continue + (loop $shape$1$continue (if (i32.eq (get_local $0) @@ -2246,10 +2224,13 @@ raw: ) (func $two-blocks (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) + (block + (br $block$2$break) + ) ) (block (call_import $check @@ -2259,12 +2240,13 @@ raw: ) (func $two-blocks-plus-code (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 77) + (br $block$2$break) ) ) (block @@ -2275,11 +2257,14 @@ raw: ) (func $loop (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block + (loop $shape$0$continue + (block $block$2$break (call_import $check (i32.const 0) ) + (block + (br $block$2$break) + ) ) (block (call_import $check @@ -2293,13 +2278,14 @@ raw: ) (func $loop-plus-code (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block + (loop $shape$0$continue + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 33) + (br $block$2$break) ) ) (block @@ -2318,18 +2304,16 @@ raw: (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) - (block - (call_import $check - (i32.const 1) - ) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) ) - (block - (call_import $check - (i32.const 2) - ) + ) + (block + (call_import $check + (i32.const 2) ) ) ) @@ -2339,23 +2323,21 @@ raw: (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (i32.const 10) (block - (i32.const 10) - (block - (call_import $check - (i32.const 1) - ) + (call_import $check + (i32.const 1) ) ) + ) + (block + (i32.const 20) (block - (i32.const 20) - (block - (call_import $check - (i32.const 2) - ) + (call_import $check + (i32.const 2) ) ) ) @@ -2363,22 +2345,21 @@ raw: ) (func $if (type $v) (local $0 i32) - (block + (block $block$3$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (br $shape$1$break) - ) + (br $block$3$break) ) ) + (br $block$3$break) ) ) (block @@ -2389,26 +2370,27 @@ raw: ) (func $if-plus-code (type $v) (local $0 i32) - (block + (block $block$3$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (i32.const -1) (block - (i32.const -1) + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (i32.const -3) - (br $shape$1$break) - ) + (i32.const -3) + (br $block$3$break) ) ) + ) + (block (i32.const -2) + (br $block$3$break) ) ) ) @@ -2420,28 +2402,26 @@ raw: ) (func $if-else (type $v) (local $0 i32) - (block + (block $block$4$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (br $shape$1$break) - ) + (br $block$4$break) + ) + ) + (block + (call_import $check + (i32.const 2) ) (block - (call_import $check - (i32.const 2) - ) - (block - (br $shape$1$break) - ) + (br $block$4$break) ) ) ) @@ -2454,20 +2434,25 @@ raw: ) (func $loop-tail (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block - (call_import $check - (i32.const 0) - ) - ) - (block - (call_import $check - (i32.const 1) + (block $block$3$break + (loop $shape$0$continue + (block $block$2$break + (call_import $check + (i32.const 0) + ) + (block + (br $block$2$break) + ) ) - (if - (i32.const 10) - (br $shape$0$continue) - (br $shape$0$break) + (block + (call_import $check + (i32.const 1) + ) + (if + (i32.const 10) + (br $shape$0$continue) + (br $block$3$break) + ) ) ) ) @@ -2479,93 +2464,81 @@ raw: ) (func $nontrivial-loop-plus-phi-to-head (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 10) + (br $block$2$break) ) ) (block - (loop $shape$1$break $shape$1$continue - (block - (call_import $check - (i32.const 1) - ) - (if - (i32.eqz - (i32.const -2) - ) - (block - (i32.const 20) - (br $shape$1$break) - ) - ) - ) - (block - (call_import $check - (i32.const 2) - ) - (if - (i32.const -6) - (block - (set_local $0 - (i32.const 4) + (block $block$7$break + (block $block$4$break + (loop $shape$1$continue + (block $block$3$break + (call_import $check + (i32.const 1) + ) + (if + (i32.const -2) + (br $block$3$break) + (block + (i32.const 20) + (br $block$7$break) + ) ) - (br $shape$1$break) ) (block - (i32.const 30) - (br $shape$1$continue) + (call_import $check + (i32.const 2) + ) + (if + (i32.const -6) + (br $block$4$break) + (block + (i32.const 30) + (br $shape$1$continue) + ) + ) ) ) ) - ) - (block - (block $shape$4$break - (if - (i32.eq - (get_local $0) - (i32.const 4) + (block + (block $block$6$break + (call_import $check + (i32.const 3) ) - (block + (if + (i32.const -10) (block (call_import $check - (i32.const 3) - ) - (block $shape$6$break - (if - (i32.const -10) - (block - (call_import $check - (i32.const 4) - ) - (block - (br $shape$6$break) - ) - ) - ) - ) - ) - (block - (call_import $check - (i32.const 5) + (i32.const 4) ) (block - (i32.const 40) - (br $shape$4$break) + (br $block$6$break) ) ) + (br $block$6$break) ) ) - ) - (block - (call_import $check - (i32.const 6) + (block + (call_import $check + (i32.const 5) + ) + (block + (i32.const 40) + (br $block$7$break) + ) ) ) ) + (block + (call_import $check + (i32.const 6) + ) + ) ) ) (func $switch (type $v) @@ -2573,43 +2546,41 @@ raw: (call_import $check (i32.const 0) ) - (block $shape$1$break - (block $switch$1$leave - (block $switch$1$default - (block $switch$1$case$3 - (block $switch$1$case$2 - (br_table $switch$1$default $switch$1$default $switch$1$case$2 $switch$1$default $switch$1$case$3 $switch$1$case$2 $switch$1$default - (i32.const -99) - ) - ) - (block - (block - (call_import $check - (i32.const 1) - ) - ) + (block $switch$1$leave + (block $switch$1$default + (block $switch$1$case$3 + (block $switch$1$case$2 + (br_table $switch$1$default $switch$1$default $switch$1$case$2 $switch$1$default $switch$1$case$3 $switch$1$case$2 $switch$1$default + (i32.const -99) ) - (br $switch$1$leave) ) (block - (i32.const 55) (block (call_import $check - (i32.const 2) + (i32.const 1) ) ) ) (br $switch$1$leave) ) (block + (i32.const 55) (block (call_import $check - (i32.const 3) + (i32.const 2) ) ) ) (br $switch$1$leave) ) + (block + (block + (call_import $check + (i32.const 3) + ) + ) + ) + (br $switch$1$leave) ) ) (func $duffs-device (type $v) @@ -2621,58 +2592,66 @@ raw: (local $5 f64) (local $6 i32) (block - (call_import $check - (i32.const 0) + (block $block$3$break + (block $block$2$break + (call_import $check + (i32.const 0) + ) + (if + (i32.const 10) + (block + (set_local $3 + (i32.const 2) + ) + (br $block$2$break) + ) + (block + (set_local $3 + (i32.const 3) + ) + (br $block$3$break) + ) + ) + ) ) + ) + (loop $shape$1$continue (if - (i32.const 10) - (set_local $3 + (i32.eq + (get_local $3) (i32.const 2) ) - (set_local $3 - (i32.const 3) + (block + (set_local $3 + (i32.const 0) + ) + (call_import $check + (i32.const 1) + ) + (block + (set_local $3 + (i32.const 3) + ) + (br $shape$1$continue) + ) ) - ) - ) - (loop $shape$1$break $shape$1$continue - (block $shape$2$break (if (i32.eq (get_local $3) - (i32.const 2) + (i32.const 3) ) (block (set_local $3 (i32.const 0) ) (call_import $check - (i32.const 1) - ) - (block - (set_local $3 - (i32.const 3) - ) - (br $shape$1$continue) - ) - ) - (if - (i32.eq - (get_local $3) - (i32.const 3) + (i32.const 2) ) (block (set_local $3 - (i32.const 0) - ) - (call_import $check (i32.const 2) ) - (block - (set_local $3 - (i32.const 2) - ) - (br $shape$1$continue) - ) + (br $shape$1$continue) ) ) ) @@ -2716,7 +2695,7 @@ optimized: ) ) (func $loop (type $v) - (loop $shape$0$break $shape$0$continue + (loop $shape$0$continue (call_import $check (i32.const 0) ) @@ -2754,21 +2733,6 @@ optimized: (i32.const 2) ) ) - (func $if-plus-code (type $v) - (call_import $check - (i32.const 0) - ) - (if - (i32.const 55) - (call_import $check - (i32.const 1) - ) - (i32.const -2) - ) - (call_import $check - (i32.const 2) - ) - ) (func $if-else (type $v) (call_import $check (i32.const 0) @@ -2787,17 +2751,19 @@ optimized: ) ) (func $loop-tail (type $v) - (loop $shape$0$break $shape$0$continue - (call_import $check - (i32.const 0) - ) - (call_import $check - (i32.const 1) - ) - (if - (i32.const 10) - (br $shape$0$continue) - (br $shape$0$break) + (block $block$3$break + (loop $shape$0$continue + (call_import $check + (i32.const 0) + ) + (call_import $check + (i32.const 1) + ) + (if + (i32.const 10) + (br $shape$0$continue) + (br $block$3$break) + ) ) ) (call_import $check @@ -2805,50 +2771,40 @@ optimized: ) ) (func $nontrivial-loop-plus-phi-to-head (type $v) - (local $0 i32) (call_import $check (i32.const 0) ) - (loop $shape$1$break $shape$1$continue - (call_import $check - (i32.const 1) - ) - (br_if $shape$1$break - (i32.const 0) - ) - (call_import $check - (i32.const 2) - ) - (if - (i32.const -6) - (block - (set_local $0 - (i32.const 4) + (block $block$7$break + (block $block$4$break + (loop $shape$1$continue + (call_import $check + (i32.const 1) + ) + (br_if $block$7$break + (i32.const 0) ) - (br $shape$1$break) - ) - (br $shape$1$continue) - ) - ) - (if - (i32.eq - (get_local $0) - (i32.const 4) - ) - (block - (call_import $check - (i32.const 3) - ) - (if - (i32.const -10) (call_import $check - (i32.const 4) + (i32.const 2) + ) + (if + (i32.const -6) + (br $block$4$break) + (br $shape$1$continue) ) ) + ) + (call_import $check + (i32.const 3) + ) + (if + (i32.const -10) (call_import $check - (i32.const 5) + (i32.const 4) ) ) + (call_import $check + (i32.const 5) + ) ) (call_import $check (i32.const 6) @@ -2889,7 +2845,7 @@ optimized: (set_local $0 (i32.const 2) ) - (loop $shape$1$break $shape$1$continue + (loop $shape$1$continue (if (i32.eq (get_local $0) diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt index 8206ac3d4..0ba8ccf94 100644 --- a/test/example/c-api-kitchen-sink.txt.txt +++ b/test/example/c-api-kitchen-sink.txt.txt @@ -375,10 +375,13 @@ ) (func $two-blocks (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) + (block + (br $block$2$break) + ) ) (block (call_import $check @@ -388,12 +391,13 @@ ) (func $two-blocks-plus-code (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 77) + (br $block$2$break) ) ) (block @@ -404,11 +408,14 @@ ) (func $loop (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block + (loop $shape$0$continue + (block $block$2$break (call_import $check (i32.const 0) ) + (block + (br $block$2$break) + ) ) (block (call_import $check @@ -422,13 +429,14 @@ ) (func $loop-plus-code (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block + (loop $shape$0$continue + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 33) + (br $block$2$break) ) ) (block @@ -447,18 +455,16 @@ (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) - (block - (call_import $check - (i32.const 1) - ) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) ) - (block - (call_import $check - (i32.const 2) - ) + ) + (block + (call_import $check + (i32.const 2) ) ) ) @@ -468,23 +474,21 @@ (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (i32.const 10) (block - (i32.const 10) - (block - (call_import $check - (i32.const 1) - ) + (call_import $check + (i32.const 1) ) ) + ) + (block + (i32.const 20) (block - (i32.const 20) - (block - (call_import $check - (i32.const 2) - ) + (call_import $check + (i32.const 2) ) ) ) @@ -492,22 +496,21 @@ ) (func $if (type $v) (local $0 i32) - (block + (block $block$3$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (br $shape$1$break) - ) + (br $block$3$break) ) ) + (br $block$3$break) ) ) (block @@ -518,26 +521,27 @@ ) (func $if-plus-code (type $v) (local $0 i32) - (block + (block $block$3$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (i32.const -1) (block - (i32.const -1) + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (i32.const -3) - (br $shape$1$break) - ) + (i32.const -3) + (br $block$3$break) ) ) + ) + (block (i32.const -2) + (br $block$3$break) ) ) ) @@ -549,28 +553,26 @@ ) (func $if-else (type $v) (local $0 i32) - (block + (block $block$4$break (call_import $check (i32.const 0) ) - (block $shape$1$break - (if - (i32.const 55) + (if + (i32.const 55) + (block + (call_import $check + (i32.const 1) + ) (block - (call_import $check - (i32.const 1) - ) - (block - (br $shape$1$break) - ) + (br $block$4$break) + ) + ) + (block + (call_import $check + (i32.const 2) ) (block - (call_import $check - (i32.const 2) - ) - (block - (br $shape$1$break) - ) + (br $block$4$break) ) ) ) @@ -583,20 +585,25 @@ ) (func $loop-tail (type $v) (local $0 i32) - (loop $shape$0$break $shape$0$continue - (block - (call_import $check - (i32.const 0) - ) - ) - (block - (call_import $check - (i32.const 1) + (block $block$3$break + (loop $shape$0$continue + (block $block$2$break + (call_import $check + (i32.const 0) + ) + (block + (br $block$2$break) + ) ) - (if - (i32.const 10) - (br $shape$0$continue) - (br $shape$0$break) + (block + (call_import $check + (i32.const 1) + ) + (if + (i32.const 10) + (br $shape$0$continue) + (br $block$3$break) + ) ) ) ) @@ -608,93 +615,81 @@ ) (func $nontrivial-loop-plus-phi-to-head (type $v) (local $0 i32) - (block + (block $block$2$break (call_import $check (i32.const 0) ) (block (i32.const 10) + (br $block$2$break) ) ) (block - (loop $shape$1$break $shape$1$continue - (block - (call_import $check - (i32.const 1) - ) - (if - (i32.eqz - (i32.const -2) - ) - (block - (i32.const 20) - (br $shape$1$break) - ) - ) - ) - (block - (call_import $check - (i32.const 2) - ) - (if - (i32.const -6) - (block - (set_local $0 - (i32.const 4) + (block $block$7$break + (block $block$4$break + (loop $shape$1$continue + (block $block$3$break + (call_import $check + (i32.const 1) + ) + (if + (i32.const -2) + (br $block$3$break) + (block + (i32.const 20) + (br $block$7$break) + ) ) - (br $shape$1$break) ) (block - (i32.const 30) - (br $shape$1$continue) + (call_import $check + (i32.const 2) + ) + (if + (i32.const -6) + (br $block$4$break) + (block + (i32.const 30) + (br $shape$1$continue) + ) + ) ) ) ) - ) - (block - (block $shape$4$break - (if - (i32.eq - (get_local $0) - (i32.const 4) + (block + (block $block$6$break + (call_import $check + (i32.const 3) ) - (block + (if + (i32.const -10) (block (call_import $check - (i32.const 3) - ) - (block $shape$6$break - (if - (i32.const -10) - (block - (call_import $check - (i32.const 4) - ) - (block - (br $shape$6$break) - ) - ) - ) - ) - ) - (block - (call_import $check - (i32.const 5) + (i32.const 4) ) (block - (i32.const 40) - (br $shape$4$break) + (br $block$6$break) ) ) + (br $block$6$break) ) ) - ) - (block - (call_import $check - (i32.const 6) + (block + (call_import $check + (i32.const 5) + ) + (block + (i32.const 40) + (br $block$7$break) + ) ) ) ) + (block + (call_import $check + (i32.const 6) + ) + ) ) ) (func $switch (type $v) @@ -702,43 +697,41 @@ (call_import $check (i32.const 0) ) - (block $shape$1$break - (block $switch$1$leave - (block $switch$1$default - (block $switch$1$case$3 - (block $switch$1$case$2 - (br_table $switch$1$default $switch$1$default $switch$1$case$2 $switch$1$default $switch$1$case$3 $switch$1$case$2 $switch$1$default - (i32.const -99) - ) - ) - (block - (block - (call_import $check - (i32.const 1) - ) - ) + (block $switch$1$leave + (block $switch$1$default + (block $switch$1$case$3 + (block $switch$1$case$2 + (br_table $switch$1$default $switch$1$default $switch$1$case$2 $switch$1$default $switch$1$case$3 $switch$1$case$2 $switch$1$default + (i32.const -99) ) - (br $switch$1$leave) ) (block - (i32.const 55) (block (call_import $check - (i32.const 2) + (i32.const 1) ) ) ) (br $switch$1$leave) ) (block + (i32.const 55) (block (call_import $check - (i32.const 3) + (i32.const 2) ) ) ) (br $switch$1$leave) ) + (block + (block + (call_import $check + (i32.const 3) + ) + ) + ) + (br $switch$1$leave) ) ) (func $duffs-device (type $v) @@ -750,58 +743,66 @@ (local $5 f64) (local $6 i32) (block - (call_import $check - (i32.const 0) + (block $block$3$break + (block $block$2$break + (call_import $check + (i32.const 0) + ) + (if + (i32.const 10) + (block + (set_local $3 + (i32.const 2) + ) + (br $block$2$break) + ) + (block + (set_local $3 + (i32.const 3) + ) + (br $block$3$break) + ) + ) + ) ) + ) + (loop $shape$1$continue (if - (i32.const 10) - (set_local $3 + (i32.eq + (get_local $3) (i32.const 2) ) - (set_local $3 - (i32.const 3) + (block + (set_local $3 + (i32.const 0) + ) + (call_import $check + (i32.const 1) + ) + (block + (set_local $3 + (i32.const 3) + ) + (br $shape$1$continue) + ) ) - ) - ) - (loop $shape$1$break $shape$1$continue - (block $shape$2$break (if (i32.eq (get_local $3) - (i32.const 2) + (i32.const 3) ) (block (set_local $3 (i32.const 0) ) (call_import $check - (i32.const 1) - ) - (block - (set_local $3 - (i32.const 3) - ) - (br $shape$1$continue) - ) - ) - (if - (i32.eq - (get_local $3) - (i32.const 3) + (i32.const 2) ) (block (set_local $3 - (i32.const 0) - ) - (call_import $check (i32.const 2) ) - (block - (set_local $3 - (i32.const 2) - ) - (br $shape$1$continue) - ) + (br $shape$1$continue) ) ) ) @@ -840,7 +841,7 @@ ) ) (func $loop (type $v) - (loop $shape$0$break $shape$0$continue + (loop $shape$0$continue (call_import $check (i32.const 0) ) @@ -878,21 +879,6 @@ (i32.const 2) ) ) - (func $if-plus-code (type $v) - (call_import $check - (i32.const 0) - ) - (if - (i32.const 55) - (call_import $check - (i32.const 1) - ) - (i32.const -2) - ) - (call_import $check - (i32.const 2) - ) - ) (func $if-else (type $v) (call_import $check (i32.const 0) @@ -911,17 +897,19 @@ ) ) (func $loop-tail (type $v) - (loop $shape$0$break $shape$0$continue - (call_import $check - (i32.const 0) - ) - (call_import $check - (i32.const 1) - ) - (if - (i32.const 10) - (br $shape$0$continue) - (br $shape$0$break) + (block $block$3$break + (loop $shape$0$continue + (call_import $check + (i32.const 0) + ) + (call_import $check + (i32.const 1) + ) + (if + (i32.const 10) + (br $shape$0$continue) + (br $block$3$break) + ) ) ) (call_import $check @@ -929,50 +917,40 @@ ) ) (func $nontrivial-loop-plus-phi-to-head (type $v) - (local $0 i32) (call_import $check (i32.const 0) ) - (loop $shape$1$break $shape$1$continue - (call_import $check - (i32.const 1) - ) - (br_if $shape$1$break - (i32.const 0) - ) - (call_import $check - (i32.const 2) - ) - (if - (i32.const -6) - (block - (set_local $0 - (i32.const 4) + (block $block$7$break + (block $block$4$break + (loop $shape$1$continue + (call_import $check + (i32.const 1) + ) + (br_if $block$7$break + (i32.const 0) ) - (br $shape$1$break) - ) - (br $shape$1$continue) - ) - ) - (if - (i32.eq - (get_local $0) - (i32.const 4) - ) - (block - (call_import $check - (i32.const 3) - ) - (if - (i32.const -10) (call_import $check - (i32.const 4) + (i32.const 2) + ) + (if + (i32.const -6) + (br $block$4$break) + (br $shape$1$continue) ) ) + ) + (call_import $check + (i32.const 3) + ) + (if + (i32.const -10) (call_import $check - (i32.const 5) + (i32.const 4) ) ) + (call_import $check + (i32.const 5) + ) ) (call_import $check (i32.const 6) @@ -1013,7 +991,7 @@ (set_local $0 (i32.const 2) ) - (loop $shape$1$break $shape$1$continue + (loop $shape$1$continue (if (i32.eq (get_local $0) diff --git a/test/example/relooper-fuzz.txt b/test/example/relooper-fuzz.txt index 6da66a8c9..b4e6c8b57 100644 --- a/test/example/relooper-fuzz.txt +++ b/test/example/relooper-fuzz.txt @@ -154,44 +154,49 @@ ) (block (block - (block - (call_import $print - (i32.const 0) - ) - (set_local $0 - (call $check) - ) - ) - (block $shape$1$break - (if - (i32.eq - (i32.rem_u - (get_local $0) - (i32.const 2) + (block $block$6$break + (block $block$5$break + (block + (call_import $print + (i32.const 0) + ) + (set_local $0 + (call $check) ) - (i32.const 0) - ) - (set_local $1 - (i32.const 6) ) - (block - (block - (call_import $print - (i32.const 8) + (if + (i32.eq + (i32.rem_u + (get_local $0) + (i32.const 2) ) - (set_local $0 - (call $check) + (i32.const 0) + ) + (block + (set_local $1 + (i32.const 6) ) + (br $block$6$break) ) (block - (br $shape$1$break) + (block + (call_import $print + (i32.const 8) + ) + (set_local $0 + (call $check) + ) + ) + (block + (br $block$5$break) + ) ) ) ) ) ) - (loop $shape$3$break $shape$3$continue - (block $shape$4$break + (loop $shape$3$continue + (block $block$5$break (if (i32.eq (get_local $1) @@ -229,7 +234,7 @@ ) ) (block - (block + (block $block$3$break (block (call_import $print (i32.const 4) @@ -261,6 +266,7 @@ ) (br $shape$3$continue) ) + (br $block$3$break) ) ) ) @@ -460,7 +466,7 @@ (call $check) ) ) - (loop $shape$3$break $shape$3$continue + (loop $shape$3$continue (if (i32.eq (get_local $0) diff --git a/test/example/relooper-fuzz1.txt b/test/example/relooper-fuzz1.txt index baef772c8..437dab062 100644 --- a/test/example/relooper-fuzz1.txt +++ b/test/example/relooper-fuzz1.txt @@ -165,26 +165,16 @@ (i32.const 3) ) (block - (block - (block - (call_import $print - (i32.const 0) - ) - (set_local $0 - (call $check) - ) - ) - (block $shape$1$break - (if - (i32.eq - (i32.rem_u - (get_local $0) - (i32.const 4) + (block $block$10$break + (block $block$4$break + (block $block$3$break + (block + (call_import $print + (i32.const 0) + ) + (set_local $0 + (call $check) ) - (i32.const 0) - ) - (set_local $1 - (i32.const 3) ) (if (i32.eq @@ -192,127 +182,87 @@ (get_local $0) (i32.const 4) ) - (i32.const 2) - ) - (block - (block - (call_import $print - (i32.const 7) - ) - (set_local $0 - (call $check) - ) - ) - (if - (i32.eq - (i32.rem_u - (get_local $0) - (i32.const 3) - ) - (i32.const 0) - ) - (block - (set_local $1 - (i32.const 3) - ) - (br $shape$1$break) - ) - (block - (set_local $1 - (i32.const 10) - ) - (br $shape$1$break) - ) - ) - ) - (set_local $1 - (i32.const 4) - ) - ) - ) - ) - ) - (block - (block $shape$3$break - (if - (i32.eq - (get_local $1) - (i32.const 3) - ) - (block - (block - (call_import $print - (i32.const 2) - ) - (set_local $0 - (call $check) - ) + (i32.const 0) ) + (br $block$3$break) (if (i32.eq (i32.rem_u (get_local $0) - (i32.const 2) - ) - (i32.const 0) - ) - (block - (set_local $1 (i32.const 4) ) - (br $shape$3$break) + (i32.const 2) ) (block - (set_local $1 - (i32.const 10) + (block + (call_import $print + (i32.const 7) + ) + (set_local $0 + (call $check) + ) + ) + (if + (i32.eq + (i32.rem_u + (get_local $0) + (i32.const 3) + ) + (i32.const 0) + ) + (br $block$3$break) + (br $block$10$break) ) - (br $shape$3$break) ) + (br $block$4$break) ) ) ) - ) - (block $shape$5$break - (if - (i32.eq - (get_local $1) - (i32.const 4) - ) - (loop $shape$6$break $shape$6$continue - (set_local $1 - (i32.const 0) - ) - (block - (call_import $print - (i32.const 3) - ) - (set_local $0 - (call $check) - ) + (block + (block + (call_import $print + (i32.const 2) ) - (block - (set_local $1 - (i32.const 4) - ) - (br $shape$6$continue) + (set_local $0 + (call $check) ) ) (if (i32.eq - (get_local $1) - (i32.const 10) - ) - (block - (call_import $print - (i32.const 9) - ) - (set_local $0 - (call $check) + (i32.rem_u + (get_local $0) + (i32.const 2) ) + (i32.const 0) ) + (br $block$4$break) + (br $block$10$break) ) ) ) + (loop $shape$6$continue + (block + (call_import $print + (i32.const 3) + ) + (set_local $0 + (call $check) + ) + ) + (block + (br $shape$6$continue) + ) + ) + ) + (block + (block + (call_import $print + (i32.const 9) + ) + (set_local $0 + (call $check) + ) + ) ) ) ) @@ -482,96 +432,70 @@ (i32.const 124) (i32.const 3) ) - (call_import $print - (i32.const 0) - ) - (if - (i32.eq - (set_local $0 + (block $block$10$break + (block $block$4$break + (call_import $print + (i32.const 0) + ) + (if + (i32.ne + (i32.rem_u + (set_local $0 + (call $check) + ) + (i32.const 4) + ) + (i32.const 0) + ) (if (i32.eq (i32.rem_u - (set_local $0 - (call $check) - ) + (get_local $0) (i32.const 4) ) - (i32.const 0) + (i32.const 2) ) - (i32.const 3) - (if - (i32.eq - (i32.rem_u - (get_local $0) - (i32.const 4) - ) - (i32.const 2) + (block + (call_import $print + (i32.const 7) ) - (block - (call_import $print - (i32.const 7) - ) - (if - (i32.eq - (i32.rem_u - (call $check) - (i32.const 3) - ) - (i32.const 0) + (br_if $block$10$break + (i32.ne + (i32.rem_u + (call $check) + (i32.const 3) ) - (i32.const 3) - (i32.const 10) + (i32.const 0) ) ) - (i32.const 4) ) + (br $block$4$break) ) ) - (i32.const 3) - ) - (block (call_import $print (i32.const 2) ) - (set_local $0 - (if - (i32.eq - (i32.rem_u - (call $check) - (i32.const 2) - ) - (i32.const 0) + (br_if $block$10$break + (i32.ne + (i32.rem_u + (call $check) + (i32.const 2) ) - (i32.const 4) - (i32.const 10) + (i32.const 0) ) ) ) - ) - (if - (i32.eq - (get_local $0) - (i32.const 4) - ) - (loop $shape$6$break $shape$6$continue + (loop $shape$6$continue (call_import $print (i32.const 3) ) (call $check) (br $shape$6$continue) ) - (if - (i32.eq - (get_local $0) - (i32.const 10) - ) - (block - (call_import $print - (i32.const 9) - ) - (call $check) - ) - ) ) + (call_import $print + (i32.const 9) + ) + (call $check) ) ) |