Skip to content

C#: Remove redundant conjunct in ssaDefReachesReadWithinBlock #6293

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 1 commit into from
Jul 16, 2021

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jul 15, 2021

My attention was drawn to this predicate because of a bad join-order

[2021-07-15 12:06:35] (483s) Tuple counts for SsaImplCommon::SsaDefReaches::ssaDefReachesReadWithinBlock#2#ffff/4@fe48da:
                      5261258218 ~1%     {5} r1 = JOIN SsaImplCommon::SsaDefReaches::ssaDefReachesRank#2#ffff_0312#join_rhs WITH SsaImplSpecific::variableRead#2#cpe#123#fff_021#join_rhs ON FIRST 2 OUTPUT Lhs.0 'bb', Rhs.2 'i', Lhs.1 'v', Lhs.3, Lhs.2 'def'
                      631031     ~5%     {5} r2 = JOIN r1 WITH SsaImplCommon::SsaDefReaches::ssaRefRank#2#fffff_01243#join_rhs ON FIRST 4 OUTPUT Rhs.4, Lhs.0 'bb', Lhs.4 'def', Lhs.2 'v', Lhs.1 'i'
                      631031     ~0%     {4} r3 = JOIN r2 WITH construct<TSsaRefKind#2,0>@dom#SsaImplCommon::SsaDefReaches::SsaRead#2#0#f ON FIRST 1 OUTPUT Lhs.3 'v', Lhs.2 'def', Lhs.1 'bb', Lhs.4 'i'
                                         return r3

where ssaDefReachesRank and variableRead were joined on just bb and v. It turns out that the variableRead(bb, i, v, _) conjunct is actually not needed, since it is implied by ssaRefRank(bb, i, v, SsaRead()). Removing the conjunct therefore both simplifies the logic, and improves the join order:

[2021-07-15 12:20:59] (4s) Tuple counts for SsaImplCommon::SsaDefReaches::ssaDefReachesReadWithinBlock#2#ffff/4@d86644:
                      941503  ~0%     {4} r1 = SCAN SsaImplCommon::SsaDefReaches::ssaDefReachesRank#2#ffff OUTPUT In.0 'bb', In.3 'v', In.2, In.1 'def'
                      941503  ~1%     {5} r2 = JOIN r1 WITH SsaImplCommon::SsaDefReaches::ssaRefRank#2#fffff_02413#join_rhs ON FIRST 3 OUTPUT Rhs.4, Lhs.0 'bb', Lhs.3 'def', Lhs.1 'v', Rhs.3 'i'
                      631031  ~0%     {4} r3 = JOIN r2 WITH construct<TSsaRefKind#2,0>@dom#SsaImplCommon::SsaDefReaches::SsaRead#2#0#f ON FIRST 1 OUTPUT Lhs.3 'v', Lhs.2 'def', Lhs.1 'bb', Lhs.4 'i'
                                      return r3

https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/1203/

@hvitved hvitved requested a review from a team as a code owner July 15, 2021 10:29
@github-actions github-actions bot added the C# label Jul 15, 2021
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Jul 15, 2021
@hvitved hvitved merged commit 8321d5f into github:main Jul 16, 2021
@hvitved hvitved deleted the csharp/ssa/remove-redundant-conjunct branch July 16, 2021 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants