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

asm goto wrong output at -O0 #110251

Closed
fuhsnn opened this issue Sep 27, 2024 · 2 comments
Closed

asm goto wrong output at -O0 #110251

fuhsnn opened this issue Sep 27, 2024 · 2 comments

Comments

@fuhsnn
Copy link

fuhsnn commented Sep 27, 2024

Godbolt: https://godbolt.org/z/3a1vYMaoq

void asm_goto_output(int *arg) {
  asm goto (
    "  subl $11, %[value];"
    "  cmpl $11, %[value]; je %l[label];"
    : [value]"+r"(*arg)
    :
    : "cc"
    : label
    );
  label:
  return;
}

int main(void) {
  int i = 22;
  asm_goto_output(&i);
  return i;
}

The output should be 11, yet clang at -O0 stores 0 to the pointed-to variable.

Looks like only the jump branch is buggy, if input is changed to another value and the fall-through path is taken, the output is correct.

Possibily related: #74483

@efriedma-quic
Copy link
Collaborator

Looks like a bug in fast regalloc. CC @nickdesaulniers

antoniofrighetto added a commit to antoniofrighetto/llvm-project that referenced this issue Mar 14, 2025
…pills

We have already ensured in 9cec2b2
that `INLINEASM_BR` output operands get spilled onto the stack, both
in the fallthrough path and in the indirect targets. Since reloads of
live-ins values into physical registers contextually happens after all
MIR instructions (and ops) have been visited, make sure such loads are
placed at the start of the block, but after prologues or `INLINEASM_BR`
spills, as otherwise this may cause stale values to be read from the
stack.

Fixes: llvm#74483, llvm#110251.
antoniofrighetto added a commit to antoniofrighetto/llvm-project that referenced this issue Mar 24, 2025
…pills

We have already ensured in 9cec2b2
that `INLINEASM_BR` output operands get spilled onto the stack, both
in the fallthrough path and in the indirect targets. Since reloads of
live-ins values into physical registers contextually happen after all
MIR instructions (and ops) have been visited, make sure such loads are
placed at the start of the block, but after prologues or `INLINEASM_BR`
spills, as otherwise this may cause stale values to be read from the
stack.

Fixes: llvm#74483, llvm#110251.
@antoniofrighetto
Copy link
Contributor

Should be fixed in ade2276, thanks for reporting!

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

4 participants