|
28 | 28 | #include "support/name.h" |
29 | 29 | #include "wasm-builder.h" |
30 | 30 | #include "ir/flat.h" |
| 31 | +#include "ir/iteration.h" |
31 | 32 | #include "ir/memory-utils.h" |
32 | 33 | #include "ir/module-utils.h" |
33 | 34 | #include "ir/names.h" |
@@ -464,6 +465,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { |
464 | 465 | } |
465 | 466 |
|
466 | 467 | void visitSetGlobal(SetGlobal* curr) { |
| 468 | + if (handleUnreachable(curr)) return; |
467 | 469 | if (!originallyI64Globals.count(curr->name)) return; |
468 | 470 | TempVar highBits = fetchOutParam(curr->value); |
469 | 471 | auto* setHigh = builder->makeSetGlobal( |
@@ -1578,6 +1580,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { |
1578 | 1580 | } |
1579 | 1581 |
|
1580 | 1582 | void visitSelect(Select* curr) { |
| 1583 | + if (handleUnreachable(curr)) return; |
1581 | 1584 | if (!hasOutParam(curr->ifTrue)) { |
1582 | 1585 | assert(!hasOutParam(curr->ifFalse)); |
1583 | 1586 | return; |
@@ -1669,6 +1672,24 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { |
1669 | 1672 | highBitVars.erase(e); |
1670 | 1673 | return ret; |
1671 | 1674 | } |
| 1675 | + |
| 1676 | + // If e.g. a select is unreachable, then one arm may have an out param |
| 1677 | + // but not the other. In this case dce should really have been run |
| 1678 | + // before; handle it in a simple way here. |
| 1679 | + bool handleUnreachable(Expression* curr) { |
| 1680 | + if (curr->type != unreachable) return false; |
| 1681 | + std::vector<Expression*> children; |
| 1682 | + for (auto* child : ChildIterator(curr)) { |
| 1683 | + if (isConcreteType(child->type)) { |
| 1684 | + child = builder->makeDrop(child); |
| 1685 | + } |
| 1686 | + children.push_back(child); |
| 1687 | + } |
| 1688 | + auto* block = builder->makeBlock(children); |
| 1689 | + assert(block->type == unreachable); |
| 1690 | + replaceCurrent(block); |
| 1691 | + return true; |
| 1692 | + } |
1672 | 1693 | }; |
1673 | 1694 |
|
1674 | 1695 | Pass *createI64ToI32LoweringPass() { |
|
0 commit comments