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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] `fpext` crashes on `half` type
        </td>
    </tr>

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

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

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

<pre>
    ## Description

When `d` (Standard Extension for Double-Precision Floating-Point) feature is on, the following code crashes RISCV backend with assertion error `VT.isInteger() == MemVT.isInteger() && "Cannot convert from FP to Int or Int -> FP!"`.

## Cause

https://github.com/llvm/llvm-project/blob/b10899d869954e1426684cbc20a43d7303075d49/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L8210-L8229

The param `VT` is `i64` type and `MemVT` is `f16`, which caused the assertion to fail.

## Minimal Reproduction

https://godbolt.org/z/EK698bYWv

### Code

```ll
define void @test(ptr %0, ptr %1) {
  %V1 = load <8 x half>, ptr %0
  %V2 = fpext <8 x half> %V1 to <8 x double>
  store <8 x double> %V2, ptr %1
  ret void
}
```

### Stack Trace

```console
llc: /root/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:8222: llvm::SDValue llvm::SelectionDAG::getLoad(llvm::ISD::MemIndexedMode, llvm::ISD::LoadExtType, llvm::EVT, const llvm::SDLoc&, llvm::SDValue, llvm::SDValue, llvm::SDValue, llvm::EVT, llvm::MachineMemOperand*): Assertion `VT.isInteger() == MemVT.isInteger() && "Cannot convert from FP to Int or Int -> FP!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=riscv64 -mattr=+d <source>
1.      Running pass 'Function Pass Manager' on module '<source>'.
2.      Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@test'
 #0 0x0000557e3ad2b15f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x354b15f)
 #1 0x0000557e3ad288b4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f11c56f2420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f11c51bf00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f11c519e859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f11c519e729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f11c51affd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000557e3aa9739a (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x32b739a)
 #8 0x0000557e3aa9e6ed llvm::SelectionDAG::getExtLoad(llvm::ISD::LoadExtType, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::EVT, llvm::MachineMemOperand*) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x32be6ed)
 #9 0x0000557e3a9c31b8 (anonymous namespace)::SelectionDAGLegalize::LegalizeLoadOps(llvm::SDNode*) LegalizeDAG.cpp:0:0
#10 0x0000557e3a9e2765 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) (.part.0) LegalizeDAG.cpp:0:0
#11 0x0000557e3a9e630c llvm::SelectionDAG::Legalize() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x320630c)
#12 0x0000557e3aaf1cec llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3311cec)
#13 0x0000557e3aaf54c8 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x33154c8)
#14 0x0000557e3aaf7192 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#15 0x0000557e39fca6ce llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#16 0x0000557e3a5647f1 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2d847f1)
#17 0x0000557e3a564a39 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2d84a39)
#18 0x0000557e3a5652b2 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2d852b2)
#19 0x0000557e38077634 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#20 0x0000557e37fbff06 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x7dff06)
#21 0x00007f11c51a0083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#22 0x0000557e3806da1e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x88da1e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WF1z26rW_jXkhrEHgayPi1w4sZ2deZO3mbqTPecqgwDZnCLQAEqd_vozINmxHLdNuzN7po3tJXjWsz5YawnqnNxoIS7B7ArMFhe081tjL_-i319W0m0vKsNfLgEmABO4EI5Z2XppNEALgOb937-3QkOQIQ4yBAEu1p5qTi2Hy50X2kmjYW0sXJiuUmLyYAWTUbhShnqpN5MHI7UHuIS1oL6zAkoHjQb4GvqtgLVRynyTegOZ4QIyS91WOPj5dn39CCvKvgrN4Tfpt5A6J2xgB4W1xgZOj1-m0t1qLzbCAlwEJYAsAFnAe9Gce4gzgDMIML6mWhsPmdHPwnpYW9PA1QP0Bt5qD42NHxNAlnD1AHACMAYZmh77ZfDaNe2cOJZvvW8dIHOAVwCvNtJvu2rKTAPwSqnn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