https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125586

            Bug ID: 125586
           Summary: [x86-64] Redundant movs around mul carry-chains
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chfast at gmail dot com
  Target Milestone: ---

In the snippet coming from multi-word by word multiplication there are
redundant register movs.

    using u64 = unsigned long;
    using u128 = unsigned __int128;
    void mul(u64 t[3], const u64 x[2], u64 y) {
        const u128 p0 = (u128)x[0] * y, p1 = (u128)x[1] * y;
        t[0] = (u64)p0;
        unsigned long long c;
        t[1] = __builtin_addcll((u64)p1, (u64)(p0 >> 64), 0, &c);
        t[2] = __builtin_addcll((u64)(p1 >> 64), 0, c, &c);
    }


        mov     rcx, rdx
        mov     rax, rdx
        mul     QWORD PTR [rsi]
        mov     r8, rax
        mov     r9, rdx
        mov     rax, rcx
        mul     QWORD PTR [rsi+8]
        mov     rcx, r9
        mov     QWORD PTR [rdi], r8
        add     rcx, rax
        mov     rax, rdx
        adc     rax, 0
        mov     QWORD PTR [rdi+8], rcx
        mov     QWORD PTR [rdi+16], rax
        ret

https://godbolt.org/z/jPx8GGnnM

Reply via email to