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

    <tr>
        <th>Summary</th>
        <td>
            [CodeGen][RISCV] LLVM regression: unnecessary copy instructions introduced by D146789
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Some regressions were reported by our CI after [D146789](https://reviews.llvm.org/D146789) was merged.

This patch introduced one additional copy instruction in some compression benchmarks compared with the original output.

There is an example reduced by ```llvm-reduce```:
```
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-linux-gnu"

define internal fastcc ptr @hc_find_func(i32 signext %0) {
  br label %2

2: ; preds = %2, %1
  %3 = phi i32 [ %5, %2 ], [ %0, %1 ]
  %4 = sub i32 0, %0
  %5 = add i32 %3, -1
  %6 = icmp ne i32 %3, 0
  %7 = icmp ult i32 %4, %0
  %8 = select i1 %6, i1 %7, i1 false
  br i1 %8, label %2, label %9

9: ; preds = %2
  ret ptr null
}
```

original output (commit 1d1b3c49531bb80bcd28870d4eafb71d97049e02):
```
hc_find_func: # @hc_find_func
        .cfi_startproc
# %bb.0:
        mv      a1, a0
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
        negw    a2, a0
        snez    a3, a1
        addiw   a1, a1, -1
        sltu    a2, a2, a0
        and     a2, a3, a2
        bnez    a2, .LBB0_1
# %bb.2:
        li      a0, 0
        ret
.Lfunc_end0:
```

after D146789 (commit 1d4d21e2e0950f6c451198e380371ee3142ce2fb):
```
hc_find_func: # @hc_find_func
        .cfi_startproc
# %bb.0:
        mv      a1, a0
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
        negw    a2, a0
        addiw a3, a1, -1
        sltu    a1, a3, a1
        sltu    a2, a2, a0
 and     a2, a1, a2
        mv      a1, a3
        bnez    a2, .LBB0_1
# %bb.2:
        li      a0, 0
 ret
.Lfunc_end0:
```

See also https://github.com/dtcxzyw/llvm-ci/issues/46 for more information.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vk9v47YT_TT0ZWCDIiVbOvgQxz__ukB6aYq9BhQ5stmVSIGk4ng_fUH9seVs0m2BooZByzOPb4bDJ3KE9_poELck25FsvxBdOFm3VUG-fb-cF6VVl-2zbRAcHh16r63xcEYXDa11ARWUF7Cdg8cvIKqADki22yfpepMXJNsTlp9CaD3hD4QdCDs4fNV49qu6fm1W1h0JO0xoVsBZeGjQHVGtCN0T-jCMv5-0h1YEeQJtgrOqk6jAGgShlA7aGlGDtO0FtPHBdTKaQBvwMXVpm3bMHUo08tQI9833ZuFQwVmHE4QTgnX6qCOV7ULbhXcpxEVrD8IAvommrWMJhkTKC5A1Hb5xXcvBcbXFxQ9UV0v_Nwh3xABKBFGLi-0CEL4HwhguG8IfcNkS_rBO-2Gprw8Jywl_SFi-NJwNtudoY-yONjgdkxwpnfbydZ0uO_PN2LNZ1tp0b8uj6a7ThlFhpQ3GMqOLpaiED1JCGxyQlJ7kS6WNeqk6IwnLNWfQ6-ctAGEZjVtINruBCaB0UIsS6-i7CxKzBsJ30DpUfkwxY4Q9xt9kmk9Yxntne9IQY5FsF43ZCIyGff882OlE0NtvJGlP4ruyJ5lQdIbIeoRQagjDMh5By3km6x6iZdNCrM8MNifa3FBdHSZY-kHIfEgKa5QBdNKHiLDhcTM-VqL2OKvn4M2jd1ba-b9iXujik0KPhA5Dv7Omq-tx2mb_oVSH8d0LAoTl0jaNDpCopOQyLTKelGVOS6lYnm-oSlFU5SZRxYamBVJGWPHZ23CnrZg24z9IbsylWMlKv_ggXGidncwRz7KyXM1eOFo0r4QWIok1EmOk1dNuR1-SGOQnn56T7wn_X38EfTEGHTxZ28IvKBS6SLHHNpwI3yfXkAaP5xiUzYMSWniD36O9V4244eMhdr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