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: unassignedclangb...@nondot.org
          Reporter: zamazan...@tut.by
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to