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

            Bug ID: 28426
           Summary: umulll_overflow with constant powers of two are not
                    well optimized
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedb...@nondot.org
          Reporter: jmuizel...@mozilla.com
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

bool k(unsigned long long i) {
        unsigned long long result;
        return __builtin_umulll_overflow(i, 4, &result);
}

compiles to:

        movl    $4, %ecx
        movq    %rdi, %rax
        mulq    %rcx
        seto    %al
        retq

A better alternative would be this code:

bool k(unsigned long long i)
{
        return i >> (64-2);
}

which compiles to:

        shrq    $62, %rdi
        setne   %al
        retq

This idiom comes from compiled rust code which does an overflow check when
allocating Vecs so it is quite prevalent.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to