Skip to content

[CIR][ThroughMLIR] Fix ForOp handling #1615

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
May 22, 2025
Merged

Conversation

terapines-osc-2
Copy link
Contributor

Currently the ForOp handling ignores everything except load, store and arithmetic in the step region. It does not detect whether the step and induction variable has already been assigned, either.

That might result to wrong behaviour:

// Ignores printf
for (int i = 0; i < n; i++, printf("\n"));

// Only increments once
for (int i = 0; i < n; i++, i++);

I choose to rewrite the detection and do an exact match of the instruction sequence for i++ and i += n. It doesn't seem easy to detect a more general pattern without phi nodes.

The new test case is xfailed, because ForOp hits an unreachable when it meets a non-canonicalized loop. We can implement that functionality later.

Copy link

github-actions bot commented May 14, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@AdUhTkJm AdUhTkJm force-pushed the cir-for branch 2 times, most recently from d3ff695 to 161f9ae Compare May 20, 2025 18:39
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

LGTM after few nits

@bcardosolopes bcardosolopes merged commit 9707b1d into llvm:main May 22, 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.

3 participants