Skip to content

Commit 28dd55b

Browse files
authored
[RISCV][GISel] Do libcall for G_FPTOSI, G_FPTOUI when no D or F support (#94613)
When compiling the following code: ```cpp #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <stdbool.h> int main() { int a; float f; scanf("%d", &a); scanf("%f", &f); a += (int)f; return a; } ``` for `-march=rv32ima_zbb` we get a libcall: ``` call scanf lw a0, -20(s0) call __fixsfsi mv a1, a0 ``` When we try to use GlobalISel we get this error: ``` error in backend: unable to legalize instruction: %9:_(s32) = G_FPTOSI %8:_(s32) (in function: main) ``` (Here is a link to a reproducer in Godblot: https://godbolt.org/z/f67vEEb41 ) The goal of this PR is to do a libcall for the legalization of `G_FPTOSI` and `G_FPTOUI` instead of doing a fallback to Selection DAG to do the same libcall later.
1 parent 4196c18 commit 28dd55b

File tree

3 files changed

+868
-1
lines changed

3 files changed

+868
-1
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
409409
getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
410410
.legalIf(all(typeInSet(0, {s32, sXLen}), typeIsScalarFPArith(1, ST)))
411411
.widenScalarToNextPow2(0)
412-
.clampScalar(0, s32, sXLen);
412+
.clampScalar(0, s32, sXLen)
413+
.libcall();
413414

414415
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
415416
.legalIf(all(typeIsScalarFPArith(0, ST), typeInSet(1, {s32, sXLen})))

0 commit comments

Comments
 (0)