<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Missed optimization for multiplication on 1.5 and 1.25"
   href="https://bugs.llvm.org/show_bug.cgi?id=43257">43257</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimization for multiplication on 1.5 and 1.25
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zamazan4ik@tut.by
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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: <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91709">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91709</a>

Godbolt playground: <a href="https://godbolt.org/z/zVQuwP">https://godbolt.org/z/zVQuwP</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>