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

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 01:07:41 PDT 2024


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

>From a5fd28ecc9aa78952e091b6d963447ee63421960 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
---
 .../SelectionDAG/LegalizeIntegerTypes.cpp      | 12 +++++++++++-
 llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll    | 18 ++++++++++++++----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index fefb0844f1ab53..b879f40dfd85a9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -2760,9 +2760,19 @@ void DAGTypeLegalizer::ExpandIntegerResult(SDNode *N, unsigned ResNo) {
   LLVM_DEBUG(dbgs() << "Expand integer result: "; N->dump(&DAG));
   SDValue Lo, Hi;
   Lo = Hi = SDValue();
+  bool NeedCustomLower = true;
+
+  // Skip the following function 'CustomLowerNode' when the operand had done
+  // `SoftenFloatResult`.
+  if (N->getOpcode() == ISD::BITCAST &&
+      getTypeAction(N->getOperand(0).getValueType()) ==
+          TargetLowering::TypeSoftenFloat &&
+      N->getValueType(ResNo) ==
+          GetSoftenedFloat(N->getOperand(0)).getValueType())
+    NeedCustomLower = false;
 
   // See if the target wants to custom expand this node.
-  if (CustomLowerNode(N, N->getValueType(ResNo), true))
+  if (NeedCustomLower && CustomLowerNode(N, N->getValueType(ResNo), true))
     return;
 
   switch (N->getOpcode()) {
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