[PATCH] D155502: [RISCV] Do not use F registers if zvfh/f/d is not specified in the architecture
Yueh-Ting (eop) Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 17 11:38:30 PDT 2023
eopXD updated this revision to Diff 541159.
eopXD marked an inline comment as done.
eopXD added a comment.
Add test case and fix if-condition for f16.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155502/new/
https://reviews.llvm.org/D155502
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/fastcc-without-f-reg.ll
Index: llvm/test/CodeGen/RISCV/fastcc-without-f-reg.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/fastcc-without-f-reg.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc -mtriple=riscv32 -mattr=+zfinx -verify-machineinstrs < %s \
+; RUN: | FileCheck -check-prefix=RV32 %s
+; RUN: llc -mtriple=riscv64 -mattr=+zfinx -verify-machineinstrs < %s \
+; RUN: | FileCheck -check-prefix=RV64 %s
+
+define dso_local float @caller(float noundef %x) local_unnamed_addr {
+; RV32-LABEL: caller:
+; RV32: # %bb.0: # %entry
+; RV32-NEXT: addi sp, sp, -16
+; RV32-NEXT: .cfi_def_cfa_offset 16
+; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
+; RV32-NEXT: .cfi_offset ra, -4
+; RV32-NEXT: sw a0, 0(sp)
+; RV32-NEXT: call f
+; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
+; RV32-NEXT: addi sp, sp, 16
+; RV32-NEXT: ret
+;
+; RV64-LABEL: caller:
+; RV64: # %bb.0: # %entry
+; RV64-NEXT: addi sp, sp, -16
+; RV64-NEXT: .cfi_def_cfa_offset 16
+; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
+; RV64-NEXT: .cfi_offset ra, -8
+; RV64-NEXT: sw a0, 0(sp)
+; RV64-NEXT: call f
+; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
+; RV64-NEXT: addi sp, sp, 16
+; RV64-NEXT: ret
+entry:
+ %0 = tail call fastcc float @f(float noundef %x)
+ ret float %0
+}
+
+define internal fastcc float @f(float noundef %x) unnamed_addr {
+; RV32-LABEL: f:
+; RV32: # %bb.0: # %entry
+; RV32-NEXT: lw a0, 0(sp)
+; RV32-NEXT: ret
+;
+; RV64-LABEL: f:
+; RV64: # %bb.0: # %entry
+; RV64-NEXT: lw a0, 0(sp)
+; RV64-NEXT: ret
+entry:
+ ret float %x
+}
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -15149,7 +15149,10 @@
}
}
- if (LocVT == MVT::f16) {
+ const RISCVSubtarget &Subtarget = TLI.getSubtarget();
+
+ if (LocVT == MVT::f16 &&
+ (Subtarget.hasStdExtZfh() || Subtarget.hasStdExtZfhmin())) {
static const MCPhysReg FPR16List[] = {
RISCV::F10_H, RISCV::F11_H, RISCV::F12_H, RISCV::F13_H, RISCV::F14_H,
RISCV::F15_H, RISCV::F16_H, RISCV::F17_H, RISCV::F0_H, RISCV::F1_H,
@@ -15161,7 +15164,7 @@
}
}
- if (LocVT == MVT::f32) {
+ if (LocVT == MVT::f32 && Subtarget.hasStdExtF()) {
static const MCPhysReg FPR32List[] = {
RISCV::F10_F, RISCV::F11_F, RISCV::F12_F, RISCV::F13_F, RISCV::F14_F,
RISCV::F15_F, RISCV::F16_F, RISCV::F17_F, RISCV::F0_F, RISCV::F1_F,
@@ -15173,7 +15176,7 @@
}
}
- if (LocVT == MVT::f64) {
+ if (LocVT == MVT::f64 && Subtarget.hasStdExtD()) {
static const MCPhysReg FPR64List[] = {
RISCV::F10_D, RISCV::F11_D, RISCV::F12_D, RISCV::F13_D, RISCV::F14_D,
RISCV::F15_D, RISCV::F16_D, RISCV::F17_D, RISCV::F0_D, RISCV::F1_D,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155502.541159.patch
Type: text/x-patch
Size: 3036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230717/b21ea51b/attachment.bin>
More information about the llvm-commits
mailing list