[llvm] [GISel][RISCV] Legalize `G_{U|S}DIVREM` (PR #93067)

Angelo Bulfone via llvm-commits llvm-commits at lists.llvm.org
Wed May 22 18:05:03 PDT 2024


boomshroom wrote:

>From what I can tell, the primary reason is just because LLVM doesn't know divrem library calls exist [because they've been explicitly set to null](https://github.com/llvm/llvm-project/blob/b91b8fea8c58e9b414e291df677b12ca44197784/llvm/include/llvm/IR/RuntimeLibcalls.def#L73-L82). This is in spite of the fact that [they're defined in compiler-rt](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/divmodsi4.c) and should be available. Not only that, but the divrem functions are directly called by div and rem.

The only reasons I can tell for them not to be enabled are to avoid auto-generated 2-output libcalls (which would explain why sincos is also set to null), and because the 128-bit versions aren't built on all targets (which doesn't make as much sense since the 128-bit libcalls for div and rem are unconditionally declared anyways).

[If the libcalls were declared in `RuntimeLibcalls.def`](https://github.com/llvm/llvm-project/pull/68462/files), then LLVM does seem fully capable of generating calls to them in the right circumstances, and even seems to pass the pointer parameter without issue.

https://github.com/llvm/llvm-project/pull/93067


More information about the llvm-commits mailing list