Skip to content

[Constraint solver] De-prioritize SIMD operators. #21231

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

Merged

Conversation

DougGregor
Copy link
Member

The new SIMD proposal introduced a number of new operators, the presence of
which causes more "expression too complex" failures. Route around the
problem by de-prioritizing those operators, visiting them only if no
other operator could be chosen. This should limit the type checker
performance cost of said operators to only those expressions that need
them OR that already failed to type-check.

Fixes rdar://problem/46541800.

The new SIMD proposal introduced a number of new operators, the presence of
which causes more "expression too complex" failures. Route around the
problem by de-prioritizing those operators, visiting them only if no
other operator could be chosen. This should limit the type checker
performance cost of said operators to only those expressions that need
them OR that already failed to type-check.

Fixes rdar://problem/46541800.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

return false;

auto func = dyn_cast<FuncDecl>(value);
if (!func)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can combine two ifs into one !(func && function->isOperator()), and same could be done for nominal using De Morgan's Law :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like breaking out the conditions here.


// Check whether we have any SIMD operators.
bool foundSIMDOperator = false;
for (const auto &choice : choices) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's actually worse to check if we have any simd operators and then sort, might be faster to simplify sort since there are not going to be thousands of operators anyway...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to avoid the malloc + copy for the common case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarification!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use llvm::find_if to make it a bit smaller :)

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Unfortunately this means if simd is included and used it would be slower because we'd check generic operators and other stuff first...

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 052d4c1

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

Copy link
Contributor

@stephentyrone stephentyrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SIMDOperators changes LGTM.

@DougGregor DougGregor force-pushed the simd-operator-type-check-perf-hack branch from a9b6c48 to 052d4c1 Compare December 12, 2018 01:35
@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a9b6c4881caec9e46a6d6a9d8cb66f0c499bb668

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a9b6c4881caec9e46a6d6a9d8cb66f0c499bb668

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 052d4c1

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

Previous failure was a spurious one from LLDB:

TIMEOUT: test_dsym (lang/swift/variables/uninitialized/TestSwiftUninitializedVariable.py)

@DougGregor
Copy link
Member Author

#21253 has a more advanced form of this hack, which should handle the newer test case @xedin came up with.

@DougGregor
Copy link
Member Author

This optimization is safe and improves things a bit, so I'm going to go ahead and merge it. The more advanced hack in #21253 is also way more dicey, so I want to hold off on that.

@DougGregor DougGregor merged commit aa50628 into swiftlang:master Dec 13, 2018
@DougGregor DougGregor deleted the simd-operator-type-check-perf-hack branch December 13, 2018 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants