<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/100444>100444</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            AMDGPU GlobalISel i64 multiply overuses v_mad_u64_u32
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AMDGPU,
            llvm:globalisel
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          arsenm
      </td>
    </tr>
</table>

<pre>
    64-bit and wider multiply over-uses v_mad_u64_u32.

```
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -o - %s | FileCheck -check-prefix=GISEL %s
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -o - %s | FileCheck -check-prefix=SDAG %s

; GISEL: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GISEL: v_mov_b32_e32 v4, v0
; GISEL: v_mov_b32_e32 v5, v1
; GISEL: v_mad_u64_u32 v[0:1], s[4:5], v4, v2, 0
; GISEL: v_mad_u64_u32 v[3:4], s[4:5], v4, v3, v[1:2]
; GISEL: v_mad_u64_u32 v[1:2], s[4:5], v5, v2, v[3:4]
; GISEL: s_setpc_b64 s[30:31]

; SDAG: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; SDAG: v_mul_lo_u32 v4, v1, v2
; SDAG: v_mul_lo_u32 v3, v0, v3
; SDAG: v_mad_u64_u32 v[0:1], s[4:5], v0, v2, 0
; SDAG: v_add3_u32 v1, v1, v3, v4
; SDAG: s_setpc_b64 s[30:31]
define i64 @mul64(i64 %a, i64 %b) {
  %mul = mul i64 %a, %b
  ret i64 %mul
}

```

There should only be one v_mad_u64_u32. The first one with the 0 add input is a simply mul_lo.

We have a custom lowering of multiply which tries to use v_mad_u64_u32, which is different from how the DAG handles this. The DAG relies on the default expansion and then reassembles the v_mad_u64_u32 later (and only custom lowers to select the scalar version when applicable). I was working on improving the default expansion in #97194 but that needs more work 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VUFv4zYT_TX0ZSBDJiXbOuhgrz8HAb4WRbOLHg1KHFlsSFEgKTn59wUpbeykbrZFUSChTPHNmzfz7CF3Tp47xJLke5IfFnzwrbEltw47vaiMeC3XWVJJD7wTcJECLehBedmrVzAj2mRw6GA8aS5Owzo7DYwuSXog6W5e1-n8N23ZHn799jNhO1CqhuSsTMVVIh0qSLS3sldI2IFrca67hGsR_lvHIdF1PxB2ODcvRZpCYiABQnMHZPMFjlLhlxbrZ0jq8Eh6i418Iezw8Pj0v_9H4P38_0HKp8Pu4TbjW96oJWR2pwuXvu48jLruPKHblNAC8KW_2anz883hHZbxpM14qhg9IaMwZoR-gTH9MTCPwNV94NVFGEm-TwnbrUh-CCGO5PuMsF0-7-eMNKx_kfYDGyNsl33OxuJK8v2KsB0NZ3-H-A18jzi_ynwn4p4vDn1fn6p1FmlYKJ-truC3kODxv3byO8l40oM6KTOVk832TKJ_AGaz6VPr7oH_iaHpXUOvZFwINjGtbkSy2b47zfm8nQIb2SHIdQYkS_Wg1hmh27ilOQ-s8-cqdJFs9lMYhFd6UEDYIcwiuI2I6Blm0X8_04Oa9W0On02nuH5t0SK41gxKgOnUK1QIpsMPUw6-tgiNtM7Hw4v0LfgWIQUuBMiuHzxIBxyc1GFaTr69G46_IbR8ROBQD84bDcpc0MruDKa5jtlLK-sWvJXowBsY3Acloe4JIx0I2TRosfPQWKOhNZcoKsyklndCBY5Wukl9eGtRBWLTRZzAhg_Kh28w75w0XZz7vsUOLHLnUFcTxQcNoLhHC4RuAz427bakKNyhwtrHWFdzxS2MaGOOS-Dnfa9kzSuFhBZLeIQLd3Ax9jn2owOpe2vGsLkvVHZAKCs2qyKDagh5uIcOUTjQxmKkgoUomShYwRdYrjZ0tc1yyopFW2as4GwrGBfNphDroinWRbap1oibLePrbCFLmtIs3dBstaUp2yzXaVpv0yKnyNmqalKSpai5VEulRr009ryQzg1YrtI0y7KF4hUqF-9ZSiteP2MnCNvtfjo8_PKN0OAioTTEErabrsVwK4aT_LCwZThJquHsSJYq6by75vHSKywnJniIoY9POP0w3l3Wf76rF4NVZet97wjbEXok9HiWvh2qZW00oceoZ3okvTW_Y-0JPcbCHKHHubaxpH8EAAD__1oIbsY">