Skip to content

Set exact flag on index_castui during iree-util-optimize-int-arithmetic#23667

Closed
amd-eochoalo wants to merge 4 commits intoiree-org:mainfrom
amd-eochoalo:eochoa/2026-03-05/drop-revert
Closed

Set exact flag on index_castui during iree-util-optimize-int-arithmetic#23667
amd-eochoalo wants to merge 4 commits intoiree-org:mainfrom
amd-eochoalo:eochoa/2026-03-05/drop-revert

Conversation

@amd-eochoalo
Copy link
Copy Markdown
Contributor

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

Since llvm/llvm-project#183395 was merged upstream,
optimization of index_cast(index_cast(x)) -> x requires the exact flag.
This pattern without the exact flag is unsound since the size of index is assumed to be 64 bits
but that is not always the case.

IREE applies this pattern when running --iree-util-optimize-int-arithmetic.
This pass uses the util dialect to prove the correctness of transforming signed operations into unsigned operations.
We take advantage of this to set the exact flag which allows the pattern to get applied soundly.

@amd-eochoalo amd-eochoalo marked this pull request as ready for review March 5, 2026 14:26
@amd-eochoalo amd-eochoalo requested a review from benvanik as a code owner March 5, 2026 14:26
@amd-eochoalo amd-eochoalo marked this pull request as draft March 5, 2026 14:48
@amd-eochoalo
Copy link
Copy Markdown
Contributor Author

Converting back to draft. I'll add exact instead on one of the passes like ConvertUnsignedI64IndexCastProducerToIndex.

@amd-eochoalo amd-eochoalo force-pushed the eochoa/2026-03-05/drop-revert branch from 4271cb5 to ee7db1d Compare March 5, 2026 15:20
@amd-eochoalo amd-eochoalo changed the title Update arithmetic optimization tests Set exact flag on index_castui during iree-util-optimize-int-arithmetic Mar 5, 2026
@amd-eochoalo amd-eochoalo marked this pull request as ready for review March 5, 2026 15:25
@amd-eochoalo amd-eochoalo requested a review from krzysz00 March 5, 2026 15:27
@amd-eochoalo
Copy link
Copy Markdown
Contributor Author

@RattataKing I'll merge after your LLVM integration, so no need to worry about this PR. I'll also point to the new LLVM branch.

@krzysz00
Copy link
Copy Markdown
Contributor

krzysz00 commented Mar 5, 2026

I'm going to flag that these patterns also exist upstream, and that there are a few other spots in IREE where we generate index_cast ops.

@amd-eochoalo
Copy link
Copy Markdown
Contributor Author

I'm closing this without merging due to it being reverted upstream. See llvm/llvm-project#184876

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