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

    <tr>
        <th>Summary</th>
        <td>
            GlobalISel AMDGPU infinite loop related to G_ADD reassociation
        </td>
    </tr>

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

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

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

<pre>
    After this commit:
```
commit 3a80bdb3169192361a6113397d9967a880de44bd (HEAD)
Author: Amara Emerson <amara@apple.com>
Date:   Mon Jul 10 00:25:49 2023 -0700

    [GlobalISel] Remove an erroneous oneuse check in the G_ADD reassociation combine.
    
    This check was unnecessary/incorrect, it was already being done by the target
    hook default implementation, and the one in the matcher was checking for a
 completely different thing. This change:
     1) Removes the check and updates affected tests which now do some more reassociations.
     2) Modifies the AMDGPU hooks which were stubbed with "return true" to also do the oneuse
        check. Not sure why I didn't do this the first time.
```
I get an infinite loop on this test case:
```
$ cat r.ll
define i32 @_amdgpu_cs_main(i32 %arg, <4 x i32> %arg1) {
bb:
 %i = insertelement <4 x i32> %arg1, i32 0, i64 0
  %i2 = icmp eq <4 x i32> %i, zeroinitializer
  %i3 = select <4 x i1> %i2, <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32> zeroinitializer
  %i4 = extractelement <4 x i32> %i3, i64 0
  %i5 = add i32 %arg, 1
  %i6 = add i32 %i5, %i4
  ret i32 %i6
}
$ ~/llvm-release/bin/llc -march=amdgcn -mcpu=gfx1100 -o /dev/null -global-isel r.ll
<hangs>
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VVuP2ygU_jXk5SgRBl_ihzykyaTblbpa7eV5hOHYpsWQBdxp-rC_fQVOZtJ2ZqUowsD5vu9cOEeEoAeLuCPVO8KYwAl9cJYwRqrjS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