Skip to content

Add two patterns to remove unused zlow.stick and zlow.unstick operations #3230

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tungld
Copy link
Collaborator

@tungld tungld commented Jul 17, 2025

ZLow operations are side-effect so they are not removed automatically if unused.

This patch adds two canonicalization patterns to remove zlow.stick and zlow.unstick operations, which has been seen in some models.

Patterns for the other zlow operations will be added on demand, as needed.

SmallVector<Value> results;
for (int64_t i : resultIndices)
results.emplace_back(op->getOperands()[i]);
bool allHasOneUse =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Confused, why would a stick with only one use be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For example:

func.func @remove_unused_stick_op(%arg0: memref<5x10xf32>) -> memref<10xf32> {
  %0 = memref.alloc() {alignment = 4096 : i64} : memref<5x10xf16, #map>
  "zlow.stick"(%arg0, %0) {layout = "2D"} : (memref<5x10xf32>, memref<5x10xf16, #map>) -> ()
  %1 = memref.alloc() {alignment = 4096 : i64} : memref<10xf32>
  return %1: memref<10xf32>
}

The result %0 of zlow.stick has only one use (that is zlow.stick), so zlow_stick can be removed.

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.

2 participants