Skip to content

[CIR][ThroughMLIR] Lower ContinueOp nested inside IfOp #1682

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
Jun 17, 2025

Conversation

terapines-osc-cir
Copy link
Contributor

As the scf dialect does not support early exits, it might be necessary to change the body of WhileOp to implement the semantics of ContinueOp. I choose to add a guard if (!cond) for everything following the continue.

@terapines-osc-cir
Copy link
Contributor Author

@felixdaas Thanks for your comment! There's still something I didn't understand about your infinite-loop example here.

void while_continue_2() {
  int i = 0, b;
  while (i < 10) {
    if (i == 5) {
      b = 3;
      continue;
    }
    i++;
  }
}

My understanding is that, the continue is supposed to skip everything after it, including i++, so an infinite loop is desired. You might found out the whole loop is skipped when you compile in -O2, but that's because infinite loop without side effect is UB and gets optimized away, which is not of our concern in lowering.
Could you please elaborate on why the i++ needs to be specially treated?

@felixdaas
Copy link
Contributor

@terapines-osc-cir oh yeah my bad youre right, I was somehow confusing the continue and break semantics here, so youre solution seems good

@bcardosolopes bcardosolopes merged commit 3401122 into llvm:main Jun 17, 2025
9 checks passed
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