@@ -168,32 +168,42 @@ static void optimizeBlock(Block* curr, Module* module, PassOptions& passOptions)
168168 if (drop) {
169169 child = drop->value ->dynCast <Block>();
170170 if (child) {
171- if (child->name .is ()) {
172- Expression* expression = child;
173- // check if it's ok to remove the value from all breaks to us
174- ProblemFinder finder (passOptions);
175- finder.origin = child->name ;
176- finder.walk (expression);
177- if (finder.found ()) {
171+ // if we move around unreachable code, type changes could occur. avoid that, as
172+ // anyhow it means we should have run dce before getting here
173+ for (auto * test : child->list ) {
174+ if (test->type == unreachable) {
178175 child = nullptr ;
179- } else {
180- // fix up breaks
181- BreakValueDropper fixer (passOptions);
182- fixer.origin = child->name ;
183- fixer.setModule (module );
184- fixer.walk (expression);
176+ break ;
185177 }
186178 }
187179 if (child) {
188- // we can do it!
189- // reuse the drop
190- drop->value = child->list .back ();
191- drop->finalize ();
192- child->list .back () = drop;
193- child->finalize ();
194- curr->list [i] = child;
195- more = true ;
196- changed = true ;
180+ if (child->name .is ()) {
181+ Expression* expression = child;
182+ // check if it's ok to remove the value from all breaks to us
183+ ProblemFinder finder (passOptions);
184+ finder.origin = child->name ;
185+ finder.walk (expression);
186+ if (finder.found ()) {
187+ child = nullptr ;
188+ } else {
189+ // fix up breaks
190+ BreakValueDropper fixer (passOptions);
191+ fixer.origin = child->name ;
192+ fixer.setModule (module );
193+ fixer.walk (expression);
194+ }
195+ }
196+ if (child) {
197+ // we can do it!
198+ // reuse the drop
199+ drop->value = child->list .back ();
200+ drop->finalize ();
201+ child->list .back () = drop;
202+ child->finalize ();
203+ curr->list [i] = child;
204+ more = true ;
205+ changed = true ;
206+ }
197207 }
198208 }
199209 }
0 commit comments