Skip to content
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

cgen: fix performance regression with x in {...} #807

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jul 19, 2023

Summary

Fix a regression in the C code generator that led to slightly less
efficient code being generated for x in set where set is a constant
set construction expression.

Details

The decision of whether to emit set construction code or to use an
|| (or) chain of comparisons was still based on the presence of the
nfAllConst flag, but node flags don't reach the code generators ever
since the introduction of the MIR and astgen, meaning that the ||
chain was always chosen for set literals with less than 8 elements.

Testing for the flag is replaced with a call to isDeepConstExpr,
restoring the originally intended behaviour (i.e., emit set construction
code for sets with a size-in-bytes <= sizeof(int)).

In addition, the other remaining usage of nfAllConst in
ccgexprs.genSetConstr is removed completely: fully constant
construction expressions are already handled by its single callsite
(ccgexprs.expr).

Summary
=======

Fix a regression in the C code generator that led to slightly less
efficient code being generated for `x in set` where set is a constant
set construction expression.

Details
=======

The decision of whether to emit set construction code or to use an
`||` (or) chain of comparisons was still based on the presence of the
`nfAllConst` flag, but node flags don't reach the code generators ever
since the introduction of the MIR and `astgen`, meaning that the `||`
chain was always chosen for set literals with less than 8 elements.

Testing for the flag is replaced with a call to `isDeepConstExpr`,
restoring the originally intended behaviour (i.e., emit set construction
code for sets with a size-in-bytes < `sizeof(int)`).

In addition, the other remaining usage of `nfAllConst` in
`ccgexprs.genSetConstr` is removed completely: fully constant
construction expression are already handled by its single callsite
(`ccgexprs.expr`).
@zerbina zerbina added the compiler/backend Related to backend system of the compiler label Jul 19, 2023
@zerbina zerbina added this to the C backend refactoring milestone Jul 19, 2023
@zerbina
Copy link
Collaborator Author

zerbina commented Jul 19, 2023

Using ccodecheck for detecting these kinds of issue works for now, but we're sooner or later going to need a different approach for reliably testing the output of the code generators.

@saem
Copy link
Collaborator

saem commented Jul 19, 2023

/merge

@github-actions
Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

@chore-runner chore-runner bot added this pull request to the merge queue Jul 19, 2023
Merged via the queue into nim-works:devel with commit 99d1174 Jul 19, 2023
18 checks passed
@zerbina zerbina deleted the cgen-small-set-performance-fix branch July 24, 2023 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/backend Related to backend system of the compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants