- Notifications
You must be signed in to change notification settings - Fork 7.8k
Optimize match(true)
#18423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:master
Are you sure you want to change the base?
Optimize match(true)
#18423
Conversation
aace896
to d14138a
CompareOf note: The optimizer is cautious with top-level code. Moving the entire code to a function gives:
That said, the optimizations are still lacking when Details
I wonder if this is better implemented as a DFA and SCCP pass. Namely, |
I'm not sure if I follow. Is the code snippet from master or this branch? For me, my PR also successfully optimizes:
Both the cast, as well as the |
I was referring to the behavior before your patch. |
do we expect this patch to improve performance? if so, how much? |
Quick test on my MacBook:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The optimization looks right to me.
The only possible problem, is the case when the eliminated temporary variable might be used several times. (e.g. in context of ??
operator).
@iluuu1994 could you please check this.
If you don't see problems, I would support this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only possible problem, is the case when the eliminated temporary variable might be used several times. (e.g. in context of ?? operator).
This would indeed be a problem for:
T2 = BOOL T1 T3 = CASE T2 ; Anything in keeps_op1_alive(), essentially. T4 = TYPE_CHECK T2 false ; After T4 = BOOL_NOT T1 T3 = CASE T2 ; T2 is no longer declared NOP
However, I don't believe such code can currently be emitted by the compiler. CASE
, CASE_STRICT
, SWITCH
are emitted for switch/match in a very specific pattern, e.g. multiple CASE
ops in sequence, followed by a single FREE instruction for the subject. There's no way to make the terminating instruction something else like a TYPE_CHECK. Thus, I think this is correct.
This optimization is already happening in the compiler for explicit `===` expressions, but not for `match()`, which also compiles to `IS_IDENTICAL`.
d14138a
to 8ffcee2
Compare
Resolves#18411