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

LR not correctly saved for inline assembly clobbering LR #47155

Closed
programmerjake opened this issue Oct 12, 2020 · 1 comment · Fixed by #76926
Closed

LR not correctly saved for inline assembly clobbering LR #47155

programmerjake opened this issue Oct 12, 2020 · 1 comment · Fixed by #76926
Assignees
Labels
backend:PowerPC bugzilla Issues migrated from bugzilla confirmed Verified by a second party miscompilation

Comments

@programmerjake
Copy link
Contributor

Bugzilla Link 47811
Version 11.0
OS Linux
CC @nemanjai,@programmerjake

Extended Description

The following IR is miscompiled:
https://gcc.godbolt.org/z/s6c6vT

target triple = "powerpc64le-unknown-linux-gnu"

define void @​f() {
call void asm sideeffect "mtlr 31", "~{lr}"()
ret void
}

Generated Assembly (trimmed to just f()):
f: # @​f
.Lfunc_begin0:
.cfi_startproc

%bb.0:

    #APP
    mtlr    31
    #NO_APP
    blr

This causes f to return to whatever address was in r31 instead of to the caller. I expect LLVM to instead store the return address that was in LR to another register or to the stack and restore it before returning.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@chenzheng1030
Copy link
Collaborator

Although trunk llc does not show the error instructions: https://godbolt.org/z/9ad8K4fG8

        mtlr    31
        addi 1, 1, 32
        ld 0, 16(1)
        mtlr 0
        blr

the assembly and the mtlr does not recognize as dependent. So the bug should still be there. And should be same with #47156, clobber ~{lr} is not same with lr8 in mtlr instruction's definitions.

@chenzheng1030 chenzheng1030 self-assigned this Jan 4, 2024
@Endilll Endilll added miscompilation confirmed Verified by a second party labels Jan 4, 2024
chenzheng1030 added a commit that referenced this issue Jan 8, 2024
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this issue Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC bugzilla Issues migrated from bugzilla confirmed Verified by a second party miscompilation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants