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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] Can't select f16 extract_vector_elt with zfhmin
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:RISC-V
      </td>
    </tr>

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

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

<pre>
    ```llvm
define half @f(<vscale x 4 x half> %v) {
  %x = extractelement <vscale x 4 x half> %v, i32 0
  ret half %x
}
```

With `-mattr=+v,+zfhmin,+zvfhmin` (or `+zfh`) we fail to select the extract_vector_elt:

```
LLVM ERROR: Cannot select: t5: f16 = extract_vector_elt t2, Constant:i64<0>
  t2: nxv4f16,ch = CopyFromReg t0, Register:nxv4f16 %0
    t1: nxv4f16 = Register %0
  t3: i64 = Constant<0>
```

However with only `-mattr=+v,+zvfhmin` we can lower this because the f16 gets softened:

```
Optimized lowered selection DAG: %bb.0 'f:'
SelectionDAG has 13 nodes:
  t0: ch,glue = EntryToken
              t2: nxv4f16,ch = CopyFromReg t0, Register:nxv4f16 %0
            t5: f16 = extract_vector_elt t2, Constant:i64<0>
 t6: i16 = bitcast t5
        t7: i32 = any_extend t6
      t9: i32 = or t7, Constant:i32<-65536>
    t10: f32 = bitcast t9
  t12: ch,glue = CopyToReg t0, Register:f32 $f10_f, t10
  t13: ch = RISCVISD::RET_GLUE t12, Register:f32 $f10_f, t12:1



Type-legalized selection DAG: %bb.0 'f:'
SelectionDAG has 12 nodes:
  t0: ch,glue = EntryToken
 t2: nxv4f16,ch = CopyFromReg t0, Register:nxv4f16 %0
          t15: nxv4i16 = bitcast t2
        t21: i64 = extract_vector_elt t15, Constant:i64<0>
      t18: i64 = or t21, Constant:i64<-65536>
    t20: f32 = RISCVISD::FMV_W_X_RV64 t18
  t12: ch,glue = CopyToReg t0, Register:f32 $f10_f, t20
  t13: ch = RISCVISD::RET_GLUE t12, Register:f32 $f10_f, t12:1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vl1vozgU_TXOi5UKX4MJDzyk-ZgdqaOR0m5n3yI-LoGtgyu4SZP59SsbSGknOyPtdKOIgLn33OtzTmwnbVvtasSYBbcsWE6SA5WmifXhCXUUTlKTn2OmvO6r9XHPvCXz5jkWVY28THTBme8VDGZMLo5tlmjkJ-7zk3vH5IozCI4MIs7C2y6X26ETZ3LJ8URNkhFq3GNN_OcQC15J4N4A0iD19SE4dYMsXPY3Q8f9o7t-q6jkTHnTfULUMLlkcGthGdx-L8p9Vff3x-5BeZzBzDQ2pQtxNxF_QV4kleZkeIsaM-JU4jCV7REzMs0WNTE5H5d_19Pd3eMXvtpsvm6YnPNFUteGejw7QIG9FkKNeRqBcwLLyMLULSW1TamUz-TCY3I1MERgMerT0S-EYrDISge2MM_ndWP2G9xx8izKBndVS9gwOe-jLakXpjknMUJyIEPKm0CSNqxSfl9n6G3U1VVl_jAveMSGv1iFTK3P_ybTqzQvyLOk5tq8YMOprFqeYpYcWnRi2C53SC1vTUFYY_5zLb4-U7WvvmPe4WHeC1GZmi_nn-ykGARpemMtERYWDMIu9X4IXM4_8TJpuZC8Njm2l4rckiznPCsZLHb6gI6cVU3N-cE8Yf3K8uvn45S7IP6-n0g5dXuItKIsackCvylGoYuS4KKS-rzFE2Gd2_RRIEXjMNPYvHf1JTC5mKogkGpkamtGx2fR514aiS58C_iRcMvdg7nKnEMCvxDetrCvbIELlOygOtN_vl88fr5fWm3lfLN62H66-3Pl6v0K0XYk3lhwdH04P-NU4y7RzoS_YT74b-b7aL-RCAbAH_wC7_wCYrxoXHOmCH651HVFZ2Mk6ykQVzOvmQremOqt0usvj9tv27-2m0fluzIfZTT4f402rHKTPJZ5JKNkgrEIIZRKKBVNyjgLi0AUoRcVEISFUipPZ0oGgAH4WZbOJlUMHvheBEr4vvCim1kOQaZEEIhcyTAD5nu4Typ9Y88GN6bZTaq2PWAshCdATXSSom7d4QIgTbInrO1abOc3fWQA9sjRxDZ3mh52LfM9XbXUvqJRRdodThwlLFjarZJBOOyVbkm7Yhq3lXTb-uTQ6LgkenZ_C1gzWO8qKg_pTWb2DNbuVNP9TJ8b87fdgWHtptEyWPczOcbwTwAAAP__8D-Q-A">