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

    <tr>
        <th>Summary</th>
        <td>
            [DAG] Failure to reassociate SMAX/SMIN/UMAX/UMIN
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            good first issue,
            llvm:codegen,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    While opt will reassociate IMINMAX intrinsics, if they appear later in DAG we fail to handle them:
```
declare i32 @llvm.umin.i32(i32, i32)
define i32 @foo(i32 %x) {
  %a = call i32 @llvm.umin.i32(i32 %x, i32 17)
  %b = call i32 @llvm.umin.i32(i32 %a, i32 17) 
  ret i32 %b
}
```
llc -mtriple=x86_64--
```
foo:                                    # @foo
        cmpl    $17, %edi
        movl    $17, %eax
        cmovael %eax, %edi
        cmpl    $17, %edi
        cmovbl  %edi, %eax
        retq
```
Godbolt: https://gcc.godbolt.org/z/45sYa7xj1

This is mainly about adding test coverage - the actual code change to add a reassociateOps call to visitIMINMAX is trivial

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVE1vnDAQ_TVwGe0K7AWWA4dNVomiKq3UtGp7qoxtwJHBFJvNJr--g2Hz1UQNMlieeX4zfp6hNOK--NEoLcH0Du6U1jBIZq3hijkJV9dXn693P0F1blCdVdwG5BxUBa6R98D6XrIBNCIHhMB-dwl3EiqmNDgDDesEEiO0DeguiPZBtAvSaBl-KSTXbJCgKIFgE2l9aNdjq7o1GgKy9d9z8FN-2lGp7nFDZcwMg4AkRwRBkJ3NQJhMDAK6B87wWO-HWPb6OBBnj6E8Q_lRBvaCAU4Ug3SwIMpFgmz_phZac1i1qHOvJcY8btPf6Wa1ehM7nZsi-_-fgNCTUEtG88PbXs_-zZTw-ZSgFOolqDWHf0Hs-JrJHJjUJ987VB-KN1GVGk6-dwKipH_eVOXSiNJoNynTONfbqerIBY6a83U9O9dmqNHygO8msb9YdryNFzL__dYoCzhapjqNJV6a0QETQnU1OGkdcHOQA6slrKbKBsbdyDRahQSOFY8OLH3cAOx5J33p7VxE6Dwoq9xjZ1nAKz8opuf4oSziNN1kNKYJCUVBRU5zFjrltCyC5Ax7LEj2cIE9Ng4-1vN-vUFKPNkNkuP0fV59x1U4Drp4JYpyzViuuWlxMRX1Mq36wdxK7nCprB0ltvxFso3jKGyKbZoTSgVLt1WcVjllGx5tM0qyPMpznEPNSqntlGhASG2MgEoNqJpnQtN8p8SHo7tJtVp2T_YWcVKs8F-kWvXAnDLemexDVZCIkDiKSJwRQsmaV4QIkiQyFiJjeYlFLvHS9Nr3J95yOBT-OOVY26ltlXX2yYmaqbqTXtOJn42uMUPx9dONak0X-nwLf-y_d-J03Q">