ykjit / yk

yk packages
https://ykjit.github.io/yk/
Other
28 stars 7 forks source link

Display and parse a guard's live variables. #1273

Closed ltratt closed 2 weeks ago

ltratt commented 3 weeks ago

Before we printed and parsed only things like:

guard true, %20

without knowing what live variables the guard has in mind. This PR both displays a guards live variables and allows them to be parsed in e.g.:

guard true, %20, [%0, %2, %7]

This has already highlighted that some guards include their condition SSA var in the live var list, and some don't. I don't know why: I'll raise a separate issue for that.

ptersilie commented 2 weeks ago

This has already highlighted that some guards include their condition SSA var in the live var list, and some don't. I don't know why

To me this just means that the guard condition just happens to be a live variable or not. For example

// Condition dies immediately after if and does not need to be deoptimised.
if x == 1 { 
   ...
}

// Condition is live after `if` and needs to be deoptimised.
int c = x == 1;
if c {
...
}
printf("%d", c);
ltratt commented 2 weeks ago

That second idiom seems a very unlikely one in real code to me... Perhaps a more realistic possibility is that the compiler is identifying duplicate conditions? Dunno.

ptersilie commented 2 weeks ago

Really? I think it can happen quite often when you pass arguments that you run checks on and foward them to other functions or use them for control flow.

int foo(bool b) {
   if (b) {
      ...
   }
   ...
   if(b) {
      ...
   }
   bar(b);
}
ltratt commented 2 weeks ago

I think it can happen quite often when you pass arguments that you run checks on and foward them to other functions or use them for control flow.

Aha, yes, using the bool type like that makes sense! I'm an idiot.