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

            Bug ID: 45868
           Summary: Missed optimization: unnecessary move with
                    division-by-multiplication
           Product: new-bugs
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

When Clang does division-by-multiplication, it seems to forget that
multiplication is commutative. It moves the numerator into %rax, but if it
moved the magic number there instead, then it wouldn't have to move the
numerator at all.

Input:

unsigned long f(unsigned long x) {
        return x / 7;
}

Actual assembly:

f:
        movabsq $2635249153387078803, %rcx
        movq    %rdi, %rax
        mulq    %rcx
        subq    %rdx, %rdi
        shrq    %rdi
        leaq    (%rdi,%rdx), %rax
        shrq    $2, %rax
        retq

Desired assembly:

f:
        movabsq $2635249153387078803, %rax
        mulq    %rdi
        subq    %rdx, %rdi
        shrq    %rdi
        leaq    (%rdi,%rdx), %rax
        shrq    $2, %rax
        retq

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to