Skip to content

Folding util.assume.int values that have a single possible value. - #21025

Merged
benvanik merged 1 commit into
mainfrom
users/benvanik/assume-fixed-fold
Jun 6, 2025
Merged

benvanik merged 1 commit into
mainfrom
users/benvanik/assume-fixed-fold

Conversation

@benvanik

@benvanik benvanik commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

This commonly arises in dynamic resource offsets on stream bindings: a bunch of umin=0, umax=0 (or whatever offset) values that ugly up the IR.

This commonly arises in dynamic resource offsets on stream bindings:
a bunch of `umin=0, umax=0` (or whatever offset) values that ugly up
the IR.
@benvanik
benvanik marked this pull request as ready for review June 5, 2025 23:35
@benvanik
benvanik enabled auto-merge (squash) June 5, 2025 23:35
} else if (auto assumption = dyn_cast<IREE::Util::IntAssumptionAttr>(
assumptions.getValue().front())) {
if (assumption.getUmin().has_value() && assumption.getUmax().has_value() &&
assumption.getUmin() == assumption.getUmax()) {

@qedawkins qedawkins Jun 6, 2025 •

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.

If you want to maximize the folding possibilities, we can do

int64_t udiv = assumption.getUdiv().value_or(1);
int64_t nearestUminCeil = (udiv + assumption.getUmin() - 1) / udiv;
if (assumption.getUmin() + udiv > assumption.getUmax()) {
  return nearestUminCeil;
}

To also catch small ranges with large divisibilities. I doubt we hit such cases in practice though.

Another way to do the same is composing with a canonicalization pattern that clamps umin/umax to their nearest divisible neighbors in which case this folder will kick in automatically.

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.

Actually doing the canonicalization might be better to keep this logic simpler.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

interesting! if you spot these in nature let me know!

@benvanik
benvanik merged commit da2f5be into main Jun 6, 2025
@benvanik
benvanik deleted the users/benvanik/assume-fixed-fold branch June 6, 2025 01:10
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
…1025)

This commonly arises in dynamic resource offsets on stream bindings: a
bunch of `umin=0, umax=0` (or whatever offset) values that ugly up the
IR.
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