[llvm] [MIPS] Fix -msingle-float doesn't work with double on O32 (PR #107543)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 02:09:27 PDT 2024


https://github.com/yingopq updated https://github.com/llvm/llvm-project/pull/107543

>From 94ba52d18462786f913ff3167712e5a2bfd206ec Mon Sep 17 00:00:00 2001
From: Ying Huang <ying.huang at oss.cipunited.com>
Date: Fri, 6 Sep 2024 04:25:39 -0400
Subject: [PATCH] [MIPS] Fix -msingle-float doesn't work with double on O32

Skip the following function 'CustomLowerNode' when the operand had
done `SoftenFloatResult`.

Fix #93052
---
 llvm/lib/Target/Mips/MipsSEISelLowering.cpp |  5 +++++
 llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll | 18 ++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
index 5c8d64e3b6e3cc..beb3321900be09 100644
--- a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
@@ -1244,6 +1244,11 @@ SDValue MipsSETargetLowering::lowerBITCAST(SDValue Op,
 
   // Bitcast double to i64.
   if (Src == MVT::f64 && Dest == MVT::i64) {
+    // Skip lower bitcast when operand0 has converted float results to integer
+    // which was done by function SoftenFloatResult.
+    if (getTypeAction(*DAG.getContext(), Op.getOperand(0).getValueType()) ==
+        TargetLowering::TypeSoftenFloat)
+      return SDValue();
     SDValue Lo =
         DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
                     DAG.getConstant(0, DL, MVT::i32));
diff --git a/llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll b/llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll
index ff8ed4d9440370..54dc40bebb0491 100644
--- a/llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll
+++ b/llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll
@@ -1,8 +1,18 @@
-; RUN: llc -march=mips -mattr=single-float  < %s | FileCheck %s
+; RUN: llc -march=mips -mcpu=mips32 -mattr=single-float -O2 < %s | FileCheck %s
+; RUN: llc -march=mips -mcpu=mips32r2 -mattr=single-float -O2 < %s | FileCheck %s
 
 define double @dofloat(double %a, double %b) nounwind {
+; CHECK-LABEL: dofloat:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    addiu $sp, $sp, -24
+; CHECK-NEXT:    sw    $ra, 20($sp)
+; CHECK-NEXT:    jal   __adddf3
+; CHECK-NEXT:    nop
+; CHECK-NEXT:    lw    $ra, 20($sp)
+; CHECK-NEXT:    jr    $ra
+; CHECK-NEXT:    addiu $sp, $sp, 24
+
 entry:
-; CHECK: __adddf3
-	fadd double %a, %b		; <double>:0 [#uses=1]
-	ret double %0
+  fadd double %a, %b ; <double>:0 [#uses=1]
+  ret double %0
 }



More information about the llvm-commits mailing list