Skip to content

[mlir][arith] Move canonicalization patterns to fold#184381

Closed
amd-eochoalo wants to merge 3 commits into
llvm:mainfrom
amd-eochoalo:eochoa/2026-03-03/narrowing
Closed

[mlir][arith] Move canonicalization patterns to fold#184381
amd-eochoalo wants to merge 3 commits into
llvm:mainfrom
amd-eochoalo:eochoa/2026-03-03/narrowing

Conversation

@amd-eochoalo
Copy link
Copy Markdown
Contributor

@amd-eochoalo amd-eochoalo commented Mar 3, 2026

#183395 added canonicalization patterns cast(cast(x, exact)) -> x.
One review comment stated the following:

Other note to future us: these should probably be folders, not canonicalization patterns. (the easy ones where there are matching pairs to cancel)

Moving these to be folders allows one to reuse this patterns in the narrow integer ranges which will run folders but not canonicalization. This allows us to remove FoldIndexCastChain.

Assisted-by: Claude

// The inner exact guarantees the iN -> index conversion is lossless,
// so the roundtrip through index preserves the value.
if (auto innerCast = getIn().getDefiningOp<IndexCastOp>()) {
if (innerCast.getIn().getType() == getType() && innerCast.getIsExact())
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 posted a question about this scenario in your previous PR:
https://github.com/llvm/llvm-project/pull/183395/changes#r2880422529
I hope we reach a reasonable resolution :) Thank you!

@amd-eochoalo
Copy link
Copy Markdown
Contributor Author

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