Skip to content

Conversation

@abadams
Copy link
Member

@abadams abadams commented Nov 4, 2025

This is an experiment in changing how we represent for loops from min/extent to min/max. In C terms, it's a change from this:

for (int x = min; x < min + extent; x++) {}

to this:

for (int x = min; x <= max; x++) {}

The reason to do this is that we need the max anyway for bounds inference, so we keep it around awkwardly as a .loop_max symbol, and then need to jump through hoops to preserve it. My thought was maybe we should just represent loops using the max to begin with, because we don't need the extent nearly so much, and we can just compute it on the fly when needed.

The result is a net deletion of code, and up to 2x faster lowering (because we can delete unused lets earlier in lowering).

I'm not comfortable merging this yet, as it's a big change to a core data type, but I wanted to open it as a PR to get buildbot testing to see what's broken.

Edit: I forgot to say the original motivation - sliding window. With a min/max loop you just bump the min in isolation. With a min/extent loop you have to also subtract from the extent, and then hope things simplify later after loop partitioning.

Now they're just regular old lets placed there for the convenience of
computing splits. They don't need to accurately reflect the loop, or be
preserved through lowering passes, etc. loop_extent was deleted
entirely. They do need to be preserved until computation bounds
inference because they provide a way to compute loop bounds as a
function of .min .max symbols that don't exist until after that point,
so you can't move them around before then.

This change was possible because allocation bounds inference doesn't
need any assistance given loops that are min/max instead of min/extent.
Also, simplify the loop extents when offloading GPU kernels and add
extra outputs in the bgu makefile.
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