Issue 131685
Summary Does not emit __udivmoddi4
Labels new issue
Assignees
Reporter purplesyringa
    Somewhat similarly to #46350, the following code is compiled suboptimally on i686 (and probably other 32-bit architectures):

```c
typedef unsigned long long u64;

struct div_mod {
    u64 div, mod;
};

struct div_mod div_mod(u64 x, u64 y) {
 struct div_mod out = {x / y, x % y};
    return out;
}
```

GCC compiles this to:

```x86asm
div_mod:
        push    ebx
        sub     esp, 24
        mov     ebx, DWORD PTR [esp+32]
        lea     eax, [esp+8]
 sub     esp, 12
        push    eax
        push    DWORD PTR [esp+64]
        push    DWORD PTR [esp+64]
        push    DWORD PTR [esp+64]
        push    DWORD PTR [esp+64]
        call    __udivmoddi4
 movq    xmm0, QWORD PTR [esp+40]
        mov     DWORD PTR [ebx], eax
        mov     eax, ebx
        mov     DWORD PTR [ebx+4], edx
 movq    QWORD PTR [ebx+8], xmm0
        add     esp, 56
        pop ebx
        ret     4
```

But Clang emits

```x86asm
div_mod:
 push    ebp
        push    ebx
        push    edi
        push    esi
 sub     esp, 12
        call    .L0$pb
.L0$pb:
        pop ebx
.Ltmp0:
        add     ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb)
        mov     ebp, dword ptr [esp + 36]
        mov     esi, dword ptr [esp + 48]
        push    esi
 push    dword ptr [esp + 48]
        push    dword ptr [esp + 48]
 push    ebp
        call    __udivdi3@PLT
        add     esp, 16
 mov     ecx, eax
        mov     edi, edx
        imul    esi, eax
 mov     ebx, dword ptr [esp + 44]
        mul     ebx
        add     edx, esi
        mov     esi, dword ptr [esp + 32]
        mov     dword ptr [esi + 4], edi
        imul    edi, ebx
        add     edi, edx
 sub     ebp, eax
        mov     edx, dword ptr [esp + 40]
        sbb edx, edi
        mov     eax, esi
        mov     dword ptr [esi], ecx
 mov     dword ptr [esi + 8], ebp
        mov     dword ptr [esi + 12], edx
        add     esp, 12
        pop     esi
        pop     edi
 pop     ebx
        pop     ebp
        ret     4
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to