Skip to content

C++: reuse unaliased SSA results when computing aliased SSA #5522

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
merged 22 commits into from
Jun 1, 2021

Conversation

rdmarsh2
Copy link
Contributor

@rdmarsh2 rdmarsh2 commented Mar 24, 2021

This PR reuses the SSA construction from the unaliased SSA IR stage when building the aliased SSA IR stage, which results in a performance speedup of about 1% across the default query suite.

@rdmarsh2 rdmarsh2 force-pushed the rdmarsh2/cpp/ssa-reuse branch 4 times, most recently from 26ba625 to 75920ff Compare April 14, 2021 23:14
@rdmarsh2 rdmarsh2 marked this pull request as ready for review April 16, 2021 00:06
@rdmarsh2 rdmarsh2 requested review from a team as code owners April 16, 2021 00:06
@rdmarsh2 rdmarsh2 requested a review from dbartol April 16, 2021 00:09
@jbj
Copy link
Contributor

jbj commented Apr 16, 2021

It's great to see this PR moving forward!

Which CPP-Differences job is associated with this PR? https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1912/?

There are test failures around autoformatting and synced files. Two tests failed:

cpp/ql/test/query-tests/Security/CWE/CWE-114/semmle/UncontrolledProcessOperation/UncontrolledProcessOperation.qlref
cpp/ql/test/library-tests/dataflow/fields/ir-path-flow.ql

Copy link
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

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

This is not a full review. Just a copy of my review comment from #5509.

Copy link

@dbartol dbartol left a comment

Choose a reason for hiding this comment

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

Only blocking issue is the commented-out code. Otherwise looks really good, with a couple minor comments.

@@ -131,6 +132,8 @@ abstract class MemoryLocation extends TMemoryLocation {
* with automatic storage duration).
*/
predicate isAlwaysAllocatedOnStack() { none() }

final predicate canReuseSSA() { any() }
Copy link

Choose a reason for hiding this comment

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

This would let a hypothetical fourth IR stage reuse anything from Aliased SSA IR, right? Maybe this should be none() until we need it to be otherwise.

@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Apr 16, 2021
@rdmarsh2
Copy link
Contributor Author

rdmarsh2 commented May 3, 2021

I've started a new changes job: internal link

@rdmarsh2
Copy link
Contributor Author

rdmarsh2 commented May 5, 2021

@jbj
Copy link
Contributor

jbj commented May 6, 2021

https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1995/ shows a speedup in SignedOverflowCheck.ql, which I think is the query that computes the whole IR 🎉. Unfortunately there's an even bigger slowdown in TaintedPath.ql, which is the query that computes the shared/cached IR data-flow predicates.

My best guess is that you've made the IR faster but that some size estimates have changed and have triggered a bad join in some code that uses the IR.

To make the next CPP-Differences fair, please merge from main into this branch. The performance improvements in #5829 could interact with your changes here.

@rdmarsh2 rdmarsh2 force-pushed the rdmarsh2/cpp/ssa-reuse branch from 247a7f4 to db85a21 Compare May 18, 2021 20:16
(
f.parameterEscapesOnlyViaReturn(operand.(PositionalArgumentOperand).getIndex())
or
f.parameterEscapesOnlyViaReturn(-1) and
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be more aesthetically pleasing to add a int getIndex() { none() } predicate to ArgumentOperand and implement it as result = -1 for ThisArgumentOperand?

@jbj
Copy link
Contributor

jbj commented May 19, 2021

I'm happy to see there's progress on this PR. Are you ready to run CPP-Differences?

@rdmarsh2
Copy link
Contributor Author

Yes. New job is here: internal link

@rdmarsh2
Copy link
Contributor Author

Rerunning the job after some overnight issues with the CI system: internal link

@rdmarsh2
Copy link
Contributor Author

Looking at those numbers, there's a range from a slowdown of 1.5% to a speedup of 4.5%, with an average. Given that most of the ones that slowed down have bigger slowdowns in Critical/NewArrayDeleteMismatch.ql, which doesn't use the IR, I think that's reflecting machine noise rather than real changes.

@MathiasVP
Copy link
Contributor

Code and CPP-differences LGTM!
I'm guessing the three new cpp/comparison-with-wider-type results are noise since they don't use the IR.

@dbartol I think your blocking issue has been fixed, right?

@jbj
Copy link
Contributor

jbj commented May 31, 2021

The performance results look great!

I'm guessing the three new cpp/comparison-with-wider-type results are noise since they don't use the IR.

I believe those "new" alerts are the ones that were fixed in #5859. If they're showing up here, it's an indication that the base commit in the comparison is too new. Unless the IR has become slower on main recently, that should not make the performance improvement any less valid.

@dbartol dbartol merged commit da14647 into main Jun 1, 2021
@dbartol dbartol deleted the rdmarsh2/cpp/ssa-reuse branch June 1, 2021 14:17
MathiasVP added a commit to MathiasVP/ql that referenced this pull request Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants