<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 - AArch64 GlobalISel miscompiles llvm.smul.with.overflow"
   href="https://bugs.llvm.org/show_bug.cgi?id=35800">35800</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>AArch64 GlobalISel miscompiles llvm.smul.with.overflow
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>GlobalISel
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>eugeni.stepanov@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=19619" name="attach_19619" title="repro bitcode">attachment 19619</a> <a href="attachment.cgi?id=19619&action=edit" title="repro bitcode">[details]</a></span>
repro bitcode

With global-isel, the following function returns 1 when %idx is -1.

define i8 @g(i64 %idx) {
entry:
  %a2 = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 1, i64 %idx)
  %a3 = extractvalue { i64, i1 } %a2, 1
  %a4 = zext i1 %a3 to i8
  ret i8 %a4
}

To reproduce, build & run the attached repro.ll. It outputs "0" with -mllvm
-fast-isel and "1" otherwise.

Assembly, fast-isel (good):

g():
 5fc:   d10043ff        sub     sp, sp, #0x10
 600:   937ffc00        asr     x0, x0, #63
 604:   eb000000        subs    x0, x0, x0
 608:   1a9f07e8        cset    w8, ne
 60c:   2a0803e1        mov     w1, w8
 610:   f90007e0        str     x0, [sp,#8]
 614:   2a0803e0        mov     w0, w8
 618:   b90007e1        str     w1, [sp,#4]
 61c:   910043ff        add     sp, sp, #0x10
 620:   d65f03c0        ret

Assembly, global-isel (bad):
g():
 608:   b24003e8        orr     x8, xzr, #0x1
 60c:   9b407d08        smulh   x8, x8, x0
 610:   d2800000        mov     x0, #0x0                        // #0
 614:   eb00011f        cmp     x8, x0
 618:   1a9f07e9        cset    w9, ne
 61c:   2a0903e0        mov     w0, w9
 620:   b3400008        bfxil   x8, x0, #0, #1
 624:   d3400108        ubfx    x8, x8, #0, #1
 628:   2a0803e9        mov     w9, w8
 62c:   53000129        ubfx    w9, w9, #0, #1
 630:   2a0903e0        mov     w0, w9
 634:   d65f03c0        ret</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>