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

C++: Fix forex recursion in sign analysis #18310

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MathiasVP
Copy link
Contributor

It's well-known that recursion through forall/forex may perform poorly. Apparently we do recursion through forex in the sign analysis library (which is part of the new range analysis library for C++). This results in some unfortunate tuple counts because the "range" part of the forall/forex gets joined with itself:

Tuple counts for _RangeAnalysisImpl::SignAnalysis::zeroBound/3#c119dcdb_RangeAnalysisImpl::SignAnalysis::zeroBound/3#__#antijoin_rhs/3@i4#L3#76559w2g after 1m28s:
  256000    ~900%         {4} r1 = JOIN `RangeAnalysisImpl::SignAnalysis::zeroBoundOk/3#a6688e7a#prev_delta` WITH num#Sign::TZero#65a6fcab CARTESIAN PRODUCT OUTPUT Lhs.0, Lhs.1 'arg1', Lhs.2 'arg2', Rhs.0
  251000    ~1835%        {3}    | JOIN WITH `RangeAnalysisImpl::SignAnalysis::zeroBound/3#c119dcdb` ON FIRST 3 OUTPUT Lhs.1 'arg1', Lhs.2 'arg2', Lhs.3 'arg0'
  692772000 ~2073%        {4}    | JOIN WITH `RangeAnalysisImpl::SignAnalysis::zeroBound/3#c119dcdb_120#join_rhs` ON FIRST 2 OUTPUT Rhs.2, Lhs.0 'arg1', Lhs.1 'arg2', Lhs.2 'arg0'
                          {4}    | AND NOT `RangeAnalysisImpl::SignAnalysis::zeroBoundOk/3#a6688e7a#prev`(FIRST 3)
  64314500  ~1238106%     {3}    | SCAN OUTPUT In.3 'arg0', In.1 'arg1', In.2 'arg2'

Luckily, there's a standard way to work around this problem by rewriting the forall/forex to recursion over integers. This PR does just that. This results in much better RA.

@Copilot Copilot bot review requested due to automatic review settings December 18, 2024 00:09
@MathiasVP MathiasVP requested a review from a team as a code owner December 18, 2024 00:09

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again, by re-requesting a review.

@github-actions github-actions bot added the C++ label Dec 18, 2024
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Dec 18, 2024
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.

1 participant