[llvm-bugs] [Bug 43619] New: Generated code preserves / pushes AX register on (some) void functions?

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 9 07:15:35 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43619

            Bug ID: 43619
           Summary: Generated code preserves / pushes AX register on
                    (some) void functions?
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mvels at google.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

I've seen various cases where clang generates 'push ax', 'pop ax' / 'add sp, 8'
pairs which I have trouble figuring out why it's there.

I don't believe there is any ABI or other reason why the compiler would or
should do so, if I am mistaken, I'd be happy to learn about the reason for the
generated code

Examples: https://godbolt.org/z/LcAQdi

This seems ok

```
void Ok(int y) {
    Bar();
    x = y;
}

        push    rbx
        mov     ebx, edi
        call    Bar()
        mov     dword ptr [rip + x], ebx
        pop     rbx
        ret
```

This is weird, why is it preserving ax?
```
void Weird1() {
    Bar();
    x = 1;
}

        push    rax
        call    Bar()
        mov     dword ptr [rip + x], 1
        pop     rax
        ret
```

This is also weird, it's pushing ax, but obviously not to preserve it?
```
void Weird2(int y, int z) {
    Bar();
    x = y + z;
}
        push    rbp
        push    rbx
        push    rax
        mov     ebx, esi
        mov     ebp, edi
        call    Bar()
        add     ebp, ebx
        mov     dword ptr [rip + x], ebp
        add     rsp, 8
        pop     rbx
        pop     rbp
        ret
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191009/a3752f85/attachment.html>


More information about the llvm-bugs mailing list