Skip to content

[Codegen] Replace LICM with a version that checks trip count - #18679

Merged
qedawkins merged 4 commits into
iree-org:mainfrom
qedawkins:safe_licm
Oct 15, 2024
Merged

qedawkins merged 4 commits into
iree-org:mainfrom
qedawkins:safe_licm

Conversation

@qedawkins

Copy link
Copy Markdown
Contributor

The upstream LICM pass does no verification that it is safe to hoist an op out of a loop (i.e. the loop has >= 1 trip count). This replaces all uses of LICM in codegen with a version that does this verification. Other phases of the compiler probably should switch as well.

@kuhar kuhar left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we fix the upstream LICM instead? I think hoisting is still fine if the hoisted ops don't have any side/memory effects -- otherwise it sounds like a bug.

@qedawkins

Copy link
Copy Markdown
Contributor Author

I filed an issue for this here: #18759

but I need this change sooner than later for this PR: #18474

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I can stamp this, but might be also worth fixing the upstream hositing for for loop, and keep this just to avoid hoisting from for_all loops.

@qedawkins

Copy link
Copy Markdown
Contributor Author

This is the last remaining change blocking #18474 (at least for CI, I'm still going to try to get a model sweep done first) and that PR is the fix to another issue and has been brewing for a while so I'd like to land it sooner rather than later.

@nirvedhmeshram nirvedhmeshram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but lets wait for approval from Mahesh or Jakub.

@Groverkss Groverkss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To avoid problems with the word "safe", can we rename this to IREELoopInvariantCodeMotion?

The upstream LICM pass does no verification that it is safe to hoist an
op out of a loop (i.e. the loop has >= 1 trip count). This replaces all
uses of LICM in codegen with a version that does this verification.
Other phases of the compiler probably should switch as well.
@qedawkins qedawkins changed the title [Codegen] Replace upstream LICM with a safer version [Codegen] Replace LICM with a version that checks trip count Oct 14, 2024
@qedawkins
qedawkins requested a review from Groverkss October 15, 2024 14:11
@qedawkins
qedawkins merged commit 3ccd4f1 into iree-org:main Oct 15, 2024
@qedawkins
qedawkins deleted the safe_licm branch October 15, 2024 17:11
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.

5 participants