Open ChiHungWei opened 2 weeks ago
@llvm/issue-subscribers-backend-risc-v
Author: None (ChiHungWei)
I don't see anything obviously wrong with your code.
The code in RISCVISelDAGToDAG.cpp shouldn't be necessary. It does the same thing as the def : Pat< (add (mul (XLenVT GPR:$rs1), (XLenVT GPR:$rs2)), GPR:$rs3), (MULADD GPR:$rs1, GPR:$rs2, GPR:$rs3) >;
in the .td file. But that shouldn't have caused the crash you're seeing.
Ubuntu 24.04.1 LTS on x86_64, LLVM 20.0.0git with riscv-gnu-toolchain installed at /opt/riscv_2
The following problem occurs while cross compiling ggml.c ,
Compiling flags(under the directory of
/llama.cpp
):/home/tomlord/workspace/jason/llvm-project/riscv-custom/bin/clang -Iggml/include -Iggml/src -Iinclude -Isrc -Icommon -I/home/tomlord/workspace/jason/llvm-project/riscv-custom/include -D_XOPEN_SOURCE=600 -D_GNU_SOURCE -D_GLIBCXX_ASSERTIONS -DGGML_USE_LLAMAFILE --gcc-toolchain=/opt/riscv_2 --sysroot=/opt/riscv_2/sysroot --target=riscv64-unknown-linux-gnu -fopenmp=libomp -v -std=c11 -fuse-ld=lld -fPIC -march=rv64gc -mabi=lp64d -O0 -g -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int -Werror=implicit-function-declaration -pthread -Wunreachable-code-break -Wunreachable-code-return -Wdouble-promotion -c ggml/src/ggml.c -o ggml/src/ggml.o
Reduced .bc file that bugpoint emits: https://github.com/ChiHungWei/For-LLVM-Bug-Report
I've added a custom instruction in llvm-project/llvm/lib/Target/RISCV/RISCVInstrInfo.td as following,
Also, in llvm-project/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp. I add a case inside the
switch (Opcode)
of functionvoid RISCVDAGToDAGISel::Select(SDNode *Node)
to help select the new custom instruction "MULADD",The newly defined instruction works well in a simple c file like this,
However, it fails when compiling
ggml.c
as shown above. I've surveyed vendor extension like RISCVInstrInfoXTHead.td and RISCVInstrInfoXVentana.td, and they use roughly the same way defining custom instructions. So I am confused what causes this issue.