<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94265>94265</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SDAG][RISCV] vnsrl pattern is broken after PR93182
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:RISC-V,
regression,
missed-optimization,
llvm:SelectionDAG
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
See the diff of file `result/rvv/193fc4d8b7725d32.S` in https://github.com/dtcxzyw/llvm-codegen-benchmark/commit/c134d37047d3e6ee2336279936f98a6eab922e77#diff-bc8f186427aa6515f00cd4d764feea719d5d90240f5602f6a8acf2e114cc9660
```
; llc -mtriple=riscv64 -mattr=+v test.ll -debug -o -
define <8 x i16> @func0000000000000000(<8 x i32> %0) #0 {
entry:
%1 = sdiv <8 x i32> %0, <i32 64, i32 64, i32 64, i32 64, i32 64, i32 64, i32 64, i32 64>
%2 = trunc <8 x i32> %1 to <8 x i16>
%3 = shl <8 x i16> %2, <i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10>
ret <8 x i16> %3
}
```
Before:
```
vsetivli zero, 8, e32, m2, ta, ma
vsra.vi v10, v8, 31
vsrl.vi v10, v10, 26
vadd.vv v8, v8, v10
vsetvli zero, zero, e16, m1, ta, ma
vnsrl.wi v10, v8, 10
vsll.vi v8, v10, 6
ret
```
After #93182:
```
vsetivli zero, 8, e32, m2, ta, ma
vsra.vi v10, v8, 31
vsrl.vi v10, v10, 26
vadd.vv v8, v8, v10
vsetvli zero, zero, e16, m1, ta, ma
vnsrl.wi v10, v8, 0
vsll.vi v8, v10, 4
li a0, -1024
vand.vx v8, v8, a0
ret
```
I think the following code breaks vnsrl (i.e., trunc (srl X, C)) pattern:
https://github.com/llvm/llvm-project/blob/2ee7f49addb60f100929d10ad24ebf1743943b0d/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp#L2609-L2618
Do we need a TLI hook to query whether (trunc (srl X, C)) is natively supported?
cc @RKSimon @topperc
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk1v2zgQ_TX0hbBADiVKPPiQxFVRbA6Lpij2SpEjmxtK9FK00vTXLyg7qfPRxS7Q4woGRVEzfG8exzPS0-R2I-KGVNek2q70Me1D3Nhkvn1_fFh1wT5u7hBp2iO1ru9p6GnvPFIiWcTp6BOBNs4zgZYr0ZvSNl1dQ2UFFHdEMupGuk_pMBFxRaAl0O5c2h-7woSBQHvGIdB6Pw9rEyzucFx3OJr9oOM9gdaEYXAZxXBRWlGzsrYCJSIIIaFWSsheNVqi7hQA1jUBkZmuO9P0vJEl1FrLilc9Y8aWtpZlj6hrrmxlFYOS9ZVk0EvdaNMDcl4ao6RklLAtYVfnUbLz7_Qorqn3hq6HFN3BIxHb6CYzy5KuB51SJGJL4HqmCadUeE_XFrvjjq4DXZ92sNi7ESkRNw39Rh2XRHygpGT9cTTs1UWgebITsNhBxQgoSkAwSurr05Y4pviYdV6eaLbilIgtnayb6Xs73ORVJ4DKMj_8gpn4cIEOC3qKx9G8hec0hZfhX3iKE--9fy0QVPBEm0vKlxh-wewHeMT0FlOcT73evpsN19iHiM_Kv3pLz9c8YXKzd_Q7xpCxmzygWAIaljHpZa5fO0ZdzI7OJ8rz4if4GyN_aXS6gTxbzdraYp7PzueRv8PwkuDTHblcePF3OM5jBn5wz3tcknwL4E8kmwuOTxQjpnf1u-oTxpzqSvAG_lf5jcr_RuTypY13VC_ra87g1btZj7aYv70IQr_C-NlZncZPNO3deL80jT54Hx7cuKO5uNMuor6fTvFQAo0rsFjiPRUJaPL6H3nlhoDKNe6gU8I4Pp_7P3ST3EOeWskhhj_R5L7R-dARaAGx7kulre0k6zljCpTlTFsoset5XQpVio7Zi31c9rsJFj_iSKC9Q48muTBurz4SaL_ouMN0Gx4wunFXmMOBgLgFydT6FiRvLhXZBvqAdES0VNM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