From bddeb18b6dcd80ff3074c2fce41a7522992cc6b5 Mon Sep 17 00:00:00 2001 From: Erik Enikeev Date: Fri, 21 Nov 2025 17:40:04 +0300 Subject: [PATCH] [Mips] Mark function calls as possibly changing FCSR (FCR31) --- llvm/lib/Target/Mips/MipsISelLowering.cpp | 5 +++++ llvm/lib/Target/Mips/MipsISelLowering.h | 2 ++ llvm/test/CodeGen/Mips/strict-fp-func.ll | 11 +++++++++++ 3 files changed, 18 insertions(+) create mode 100644 llvm/test/CodeGen/Mips/strict-fp-func.ll diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp index eec908e453724..99a4724a97851 100644 --- a/llvm/lib/Target/Mips/MipsISelLowering.cpp +++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp @@ -3060,6 +3060,11 @@ SDValue MipsTargetLowering::lowerSTRICT_FP_TO_INT(SDValue Op, return DAG.getMergeValues({Result, Op.getOperand(0)}, Loc); } +ArrayRef MipsTargetLowering::getRoundingControlRegisters() const { + static const MCPhysReg RCRegs[] = {Mips::FCR31}; + return RCRegs; +} + //===----------------------------------------------------------------------===// // Calling Convention Implementation //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/Mips/MipsISelLowering.h b/llvm/lib/Target/Mips/MipsISelLowering.h index 7c489b3b268a4..d68204e406fdb 100644 --- a/llvm/lib/Target/Mips/MipsISelLowering.h +++ b/llvm/lib/Target/Mips/MipsISelLowering.h @@ -719,6 +719,8 @@ class TargetRegisterClass; return true; } + ArrayRef getRoundingControlRegisters() const override; + /// Emit a sign-extension using sll/sra, seb, or seh appropriately. MachineBasicBlock *emitSignExtendToI32InReg(MachineInstr &MI, MachineBasicBlock *BB, diff --git a/llvm/test/CodeGen/Mips/strict-fp-func.ll b/llvm/test/CodeGen/Mips/strict-fp-func.ll new file mode 100644 index 0000000000000..a0918f9e1caef --- /dev/null +++ b/llvm/test/CodeGen/Mips/strict-fp-func.ll @@ -0,0 +1,11 @@ +; RUN: llc -mtriple=mips -stop-after=finalize-isel %s -o - | FileCheck %s + +define float @func_02(float %x, float %y) strictfp nounwind { +; CHECK-LABEL: name: func_02 +; CHECK: JAL @func_01, {{.*}}, implicit-def $fcr31 + %call = call float @func_01(float %x) strictfp + %res = call float @llvm.experimental.constrained.fadd.f32(float %call, float %y, metadata !"round.dynamic", metadata !"fpexcept.ignore") strictfp + ret float %res +} + +declare float @func_01(float)