Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbreak YKD_OPT=0. #1523

Merged
merged 1 commit into from
Dec 20, 2024
Merged

Unbreak YKD_OPT=0. #1523

merged 1 commit into from
Dec 20, 2024

Conversation

ltratt
Copy link
Contributor

@ltratt ltratt commented Dec 20, 2024

When adding support for loop peeling, we forgot that loops are only peeled when optimisations are turned on. When they were turned off, we generated code with no backjump e.g.:

; %294: ptr = load %293
mov rsi, [rdi+0x588]
; header_end [...]
; Deopt ID for guard 0
push rsi
mov rsi, 0x00

Notice no jmp between header_end and Deopt. That meant that we fell through to whichever guard's deopt happened to come first, with confusing results. For example, before this commit the new test ykd_opt_off would print:

10
9
8
7: 7

even though the code shows this is clearly "impossible":

if (i < 7)
  printf("7: ");

This commit not only fixes that, but brings a bit more order to three kinds of traces we can compile: "header only" traces (most tests, and when YKD_OPT=0); "header and body" traces (with loop peeling); and "side traces". A new TraceKind captures these, and allows us to simplify quite a bit of code in the x64 backend, which no longer has to guess what kind of trace it has.

Perhaps inevitably this also showed up a few tests where we'd muddled header and body.

When adding support for loop peeling, we forgot that loops are only
peeled when optimisations are turned on. When they were turned off, we
generated code with no backjump e.g.:

```
; %294: ptr = load %293
mov rsi, [rdi+0x588]
; header_end [...]
; Deopt ID for guard 0
push rsi
mov rsi, 0x00
```

Notice no `jmp` between `header_end` and `Deopt`. That meant that we
fell through to whichever guard's deopt happened to come first, with
confusing results. For example, before this commit the new test
`ykd_opt_off` would print:

```
10
9
8
7: 7
```

even though the code shows this is clearly "impossible":

```rust
if (i < 7)
  printf("7: ");
```

This commit not only fixes that, but brings a bit more order to three
kinds of traces we can compile: "header only" traces (most tests, and
when `YKD_OPT=0`); "header and body" traces (with loop peeling); and
"side traces". A new `TraceKind` captures these, and allows us to
simplify quite a bit of code in the x64 backend, which no longer has to
guess what kind of trace it has.

Perhaps inevitably this also showed up a few tests where we'd muddled
header and body.
@ltratt ltratt mentioned this pull request Dec 20, 2024
@vext01 vext01 added this pull request to the merge queue Dec 20, 2024
Merged via the queue into ykjit:master with commit 7565ece Dec 20, 2024
2 checks passed
@ltratt ltratt deleted the unbreak_ykd_opt_zero branch December 24, 2024 08:44
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