Skip to content

Comments

Deal with guard contradictions caused by peeling.#2094

Merged
vext01 merged 1 commit intoykjit:masterfrom
ltratt:guard_contradictions
Feb 21, 2026
Merged

Deal with guard contradictions caused by peeling.#2094
vext01 merged 1 commit intoykjit:masterfrom
ltratt:guard_contradictions

Conversation

@ltratt
Copy link
Contributor

@ltratt ltratt commented Feb 20, 2026

When we peel we can discover that the loop isn't control-flow stable on the second iteration. If we fail to realise that, we can then optimise things incorrectly. This commit deals with that.

The approach this commit takes is that, as soon as a contradiction is discovered, we abandon the peel entirely. This isn't the only thing we could do: we could (as jitc_yk used to) terminate the peel early, knowing that the final guard will always fail. I'm not sure this is worth it: the peel could end up creating extra sidetraces, and that will probably nullify whatever benefit we get from optimising the partially peeled iteration. We can revisit this later if we think it's worth it.

This fixes a openresty test case, and also found a contradiction (an obvious one in retrospect!) in the unit tests.

When we peel we can discover that the loop isn't control-flow stable on
the second iteration. If we fail to realise that, we can then optimise
things incorrectly. This commit deals with that.

The approach this commit takes is that, as soon as a contradiction is
discovered, we abandon the peel entirely. This isn't the only thing we
could do: we could (as jitc_yk used to) terminate the peel early,
knowing that the final guard will always fail. I'm not sure this is
worth it: the peel could end up creating extra sidetraces, and that will
probably nullify whatever benefit we get from optimising the partially
peeled iteration. We can revisit this later if we think it's worth it.

This fixes a openresty test case, and also found a contradiction (an
obvious one in retrospect!) in the unit tests.
@ltratt ltratt force-pushed the guard_contradictions branch from d2acc39 to cccfd4a Compare February 21, 2026 08:47
@vext01 vext01 added this pull request to the merge queue Feb 21, 2026
Merged via the queue into ykjit:master with commit 91f71c3 Feb 21, 2026
2 checks passed
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