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 inline int behavior #984

Open
sarranz opened this issue Dec 10, 2024 · 3 comments
Open

Unexpected inline int behavior #984

sarranz opened this issue Dec 10, 2024 · 3 comments
Labels

Comments

@sarranz
Copy link
Collaborator

sarranz commented Dec 10, 2024

This program

export
fn bad_inline_int(reg ptr u64[1] p) -> reg u64 {
    reg u64 x = 0;
    inline int i = (int)(x * 4);

    i *= 2;
    x = p.[i];
    return x;
}

compiles to a functionally equivalent program. However, it's really unpleasant that we can put a runtime value in an inline int. I'm adding it here for future reference, but also asking the question of whether we want to disallow this in the future.

This causes problems with the RSB checker, because for loop counters must become transient (they may contain runtime variables) and there is no way to protect them.

Also, it entails re-computing the address many times (if we have many accesses like p.[i], the multiplication will be performed ever time).

@sarranz
Copy link
Collaborator Author

sarranz commented Dec 13, 2024

We really need inline booleans to get propagated even if they are not constants, for instance for

inline bool b = x < 0;
if (b) { ... }

where we can't use reg bool.

@vbgl
Copy link
Member

vbgl commented Dec 13, 2024

Is x inline? Otherwise looks like b should be reg.

@sarranz
Copy link
Collaborator Author

sarranz commented Dec 13, 2024

Indeed, but we need propagation for this example, which fails in register allocation:

export fn f() -> reg u64 {
  reg u64 x;
  x = 1;

  reg bool cf zf sf of b;
  ?{cf, zf, sf, of} = #CMP(x, 0);
  b = _uGT(of, cf, sf, zf);

  reg u64 y;
  y = 2;
  x = y if b;
  return x;
}

because the line with _uGT doesn't have the AT_inline tag. I believe that this is the only way where the propagation part of propagate inline is needed. The example succeeds if we move b inside the ?{ ... }, because pretyping inserts b = _uGT(...); // bool:i, and then propagate inline looks for AT_inline (not for inline variables). I tried naively removing the propagation, but then we can't use ?{ ... }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants