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

Unexpected failure of register allocation #340

Closed
vbgl opened this issue Feb 1, 2023 · 1 comment
Closed

Unexpected failure of register allocation #340

vbgl opened this issue Feb 1, 2023 · 1 comment

Comments

@vbgl
Copy link
Member

vbgl commented Feb 1, 2023

The Jasmin compiler cannot compile the following program.

inline fn xor(reg u256 a b) -> reg u256 {
  reg u256 c;
  c = a ^ b;
  return c;
}

export
fn main(reg u256 x) -> reg u256 {
  reg u256[1] a;
  a[0] = x;
  x = xor(a[0], a[0]);
  return x;
}

The computation of conflicts during register allocation is not precise enough.

When all u256 are changed into u64, the error goes away (but a warning remains): this discrepancy is suspicious.

@vbgl
Copy link
Member Author

vbgl commented Jul 12, 2023

This particular example has been fixed in #341.

The difference in behavior when using general purpose registers (when values are 64-bit wide) instead of vector registers (when values are 256-bit wide) can be explained by the difference in calling conventions: with 64-bit registers, the argument x to the export function comes in a different register than the returned value and the result of the xor must be at the same place as its first argument; a copy is necessary. With 256-bit registers however, arguments and returned values use the same register (and even if it were not the case, the wide xor instruction can put its result in any desired wide register).

The weakness of register-allocation might still be present, but without a test-case allowing to reproduce it, I suggest to close this issue.

@vbgl vbgl closed this as completed Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant