[llvm-bugs] [Bug 43257] New: Missed optimization for multiplication on 1.5 and 1.25

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 9 06:44:48 PDT 2019


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

            Bug ID: 43257
           Summary: Missed optimization for multiplication on 1.5 and 1.25
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zamazan4ik at tut.by
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

On x86_32 for any number X of type (unsigned, unsigned short, unsigned char)
multiplication by 1.5 with a conversion back to unsigned with any rounding mode
produces the exactly same result as if X + (X >> 1).

Same holds for 1.25:
unsigned(X * 1.25) == unsigned(X + (X >> 2))

The above transformation allows to emit a short code without floating point
computations:

test2(unsigned int):                              # @test2(unsigned int)
        mov     eax, edi
        shr     eax
        lea     eax, [rax + rdi]
        ret

Instead of:

test(unsigned int):                               # @test(unsigned int)
        mov     eax, edi
        cvtsi2sd        xmm0, rax
        mulsd   xmm0, qword ptr [rip + .LCPI0_0]
        cvttsd2si       rax, xmm0
        ret

Same issue in GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91709

Godbolt playground: https://godbolt.org/z/zVQuwP

-- 
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/20190909/e253b66b/attachment-0001.html>


More information about the llvm-bugs mailing list