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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Missing optimization : fold `mul (phi a, b), (phi b, a) to mul a, b` to `mul a, b`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Similar to #73904

Alive2 proof: https://alive2.llvm.org/ce/z/RDGBSJ
Missed example: https://godbolt.org/z/9qK8G8o16

### Description:
```llvm
define i8 @src(i1 %c, i8 %a, i8 %b)  {
entry:
  br i1 %c, label %then, label %end
then:
  call void @dummy()
  br label %end
end:
  %phi1 = phi i8 [%a, %entry], [%b, %then]
  %phi2 = phi i8 [%b, %entry], [%a, %then]
  %mul = mul i8 %phi1, %phi2
  ret i8 %mul
}
```
can be folded to:
```llvm
define i8 @tgt(i1 %c, i8 %a, i8 %b) {
entry:
 br i1 %c, label %then, label %end
then:
  call void @dummy()
  br label %end
end:
  %mul = mul i8 %a, %b
  ret i8 %mul
}
```

### Real-world motivation

This snippet of IR is derived from [src/redis/evict.c](https://github.com/redis/redis/blob/unstable/src/evict.c) (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:

**Let me know if you can confirm that it's an optimization opportunity, thanks.**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU9v6zYM_zTKhWigyHFsH3xoG-Sh-4MBfTvsKllMzD1Z8iQ5Xd6nHyQnTdqiw8NOA4woEsmfKPJHUoZAB4vYsvKBlduFnGLvfPvHY39aKKdP7VcayEgP0QETRVU0fM34lvH7-ffe0BEFjN65PSvuoY9xDKy4Z2LHxE5m6dKY47B0_sDErkMmdt-Z2D1vvzx8_WkG-ZVCQA34txxGgx9hDk4r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