Skip to content

[compiler] remove uses of memref::ExpandOps pass - #21113

Merged
ftynse merged 1 commit into
mainfrom
users/ftynse/remove-memref-expand-ops
Jun 19, 2025
Merged

ftynse merged 1 commit into
mainfrom
users/ftynse/remove-memref-expand-ops

Conversation

@ftynse

@ftynse ftynse commented Jun 17, 2025

Copy link
Copy Markdown
Contributor

This pass currently performs two rewrites:

  1. incorrectly rewrite atomic_rmw for floating-point min/max, see ROCDL lowering generates invalid IR for memref.atomic_rmw maximumf #21101;
  2. rewrite reshape into reinterpret_cast.

The rewrite 1 was added years ago, prior to LLVM IR supporting floating-point atomics sufficiently and is no longer necessary. I will remove it upstream anyway.

The rewrite 2 looks like a canonicalizaiton and it is unclear why it was put into a separate pass, it will likely not remain there. It may have some minor effect on performance if this rewrite is important to simplify address computation, at which point it belongs to the set of canonicalization patterns.

In general, I highly suspect that the usage of this pass was either cargo-culted from existing sub-pipelines or confused with --expand-strided-metadata, which is both necessary for lowering and beneficial for address computation performance.

This pass currently performs two rewrites:

  1. *incorrectly* rewrite `atomic_rmw` for floating-point min/max, see #21101;
  2. rewrite `reshape` into `reinterpret_cast`.

The rewrite 1 was added years ago, prior to LLVM IR supporting floating-point
atomics sufficiently and is no longer necessary. I will remove it upstream
anyway.

The rewrite 2 looks like a canonicalizaiton and it is unclear why it was put
into a separate pass, it will likely not remain there. It may have some minor
effect on performance if this rewrite is important to simplify address
computation, at which point it belongs to the set of canonicalization patterns.

In general, I highly suspect that the usage of this pass was either
cargo-culted from existing sub-pipelines or confused with
`--expand-strided-metadata`, which is both necessary for lowering and
beneficial for address computation performance.

Signed-off-by: Alex Zinenko <[email protected]>
@ftynse

ftynse commented Jun 17, 2025

Copy link
Copy Markdown
Contributor Author

If somebody knows whether the reshape -> reinterpret_cast rewrite is exercised somewhere, I'm interested

@qedawkins qedawkins 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.

I believe all cases where we need reshape/subview -> reinterpret_cast happen in memref-expand-strided-metadata. And if that's not the case, we should change that to be true, so this makes sense to me.

@ftynse

ftynse commented Jun 17, 2025

Copy link
Copy Markdown
Contributor Author

AFAICS, IREE is not using memref::ReshapeOp directly, only expand/collapse that are more specific and are indeed handled by the strided metadata pass

@qedawkins

Copy link
Copy Markdown
Contributor

Oh, by reshape I thought you meant expand/collapse. Yes, we don't use reshape anywhere so should be good to drop.

@ftynse
ftynse merged commit 5d29ed6 into main Jun 19, 2025
@ftynse
ftynse deleted the users/ftynse/remove-memref-expand-ops branch June 19, 2025 14:07
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
This pass currently performs two rewrites:

1. *incorrectly* rewrite `atomic_rmw` for floating-point min/max, see
#21101;
  2. rewrite `reshape` into `reinterpret_cast`.

The rewrite 1 was added years ago, prior to LLVM IR supporting
floating-point atomics sufficiently and is no longer necessary. I will
remove it upstream anyway.

The rewrite 2 looks like a canonicalizaiton and it is unclear why it was
put into a separate pass, it will likely not remain there. It may have
some minor effect on performance if this rewrite is important to
simplify address computation, at which point it belongs to the set of
canonicalization patterns.

In general, I highly suspect that the usage of this pass was either
cargo-culted from existing sub-pipelines or confused with
`--expand-strided-metadata`, which is both necessary for lowering and
beneficial for address computation performance.

Signed-off-by: Alex Zinenko <[email protected]>
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