Skip to content

Conversation

liushuyu
Copy link
Contributor

@liushuyu liushuyu commented Sep 5, 2022

  • backend: correctly formulate the exit condition. Previously the exit condition was treated the same as the loop condition (which is the inverse condition of the exit condition). Now, this is corrected.

Should fix #1523

... previously the exit condition was treated the same as the loop
condition (which is the inverse condition of the exit condition). Now
this is corrected.
@liushuyu
Copy link
Contributor Author

liushuyu commented Sep 6, 2022

The fixed original tree (from #1523) now looks like this:

__attribute__((cdecl))
u64 const_eval_oeis_a006884::test ()
{
  u64 n = 113383;

    u64 RUSTTMP.0;
    u64 n = 113383;
  while (1)
    {
      {
        <D.82>:;
        if (n == 1) break;
        {
                    u64 RUSTTMP.1;
          if ((n & 1) == 0)
            {
              {
                RUSTTMP.1 = n / 2;
              }
            }
          else
            {
              {
                RUSTTMP.1 = n * 3 + 1;
              }
            }
          n = RUSTTMP.1;
        }
      }
    }
  return n;
}

@dkm
Copy link
Member

dkm commented Sep 6, 2022

Looks like we don't have many execution test using any loop yet :D

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

Please add the testcase without const functions to make sure that the exit code is correct. Otherwise, LGTM :) Thanks!

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

LGTM good catch this was my bad doing too much copy paste

@philberty
Copy link
Member

bors r+

@bors
Copy link
Contributor

bors bot commented Sep 8, 2022

Build succeeded:

@bors bors bot merged commit f03760b into Rust-GCC:master Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

backend: incorrect code optimization on while loops
4 participants