[NFC] Allow SubTypes::iterSubTypes to stop early#8573
Conversation
| @@ -332,27 +332,23 @@ struct FunctionOptimizer : public WalkerPass<PostWalker<FunctionOptimizer>> { | |||
| // as having failed. | |||
| auto fail = false; | |||
There was a problem hiding this comment.
nit: Maybe it would be useful for iterSubTypes to return a bool indicating whether it returned early or not? Seems like we could replace this variable with that return value if we had it.
tlively
left a comment
There was a problem hiding this comment.
LGTM as a minimal fix, but I think it would be even nicer to replace iterSubtypes with a proper iterator so the users can be in full control. Maybe Gemini could crank that out. There is a similar iterator over a tree in Unsubtyping.cpp that could be mostly copied. We could also experiment with using C++20 coroutines to simplify the code for such an iterator, but perhaps that would best be done separately.
|
@tlively Interesting, yeah, maybe an iterator would be even better. I'll land this as a perf win, and look into pure refactorings later (i.e. this is a minimal change to get the speedup, and later changes will be larger but not alter speed). |
In ConstantFieldPropagation this is important: we scan subtypes
to check if they all have 2 possible values we can
ref.testbetween.In the common case there are many values and we can stop early.
This makes the pass 4.2x faster on a large Dart testcase, and
-O3overall 3.5% faster.Fun fact, the test that is added to here was slightly wrong before:
lacking a rec group, types B and C were actually identical, so we
didn't fully test what we thought we did.