Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

yingopq
Copy link
Contributor

@yingopq yingopq commented Sep 6, 2024

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

Fix #93052

@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Sep 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2024

@llvm/pr-subscribers-llvm-selectiondag

Author: None (yingopq)

Changes

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

Fix #93052


Full diff: https://github.com/llvm/llvm-project/pull/107543.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp (+11-1)
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()) {

@arsenm
Copy link
Contributor

arsenm commented Sep 6, 2024

Needs tests

@wzssyqa wzssyqa changed the title [MIPS] Fix -msingle-float doesn't work with O32 [MIPS] Fix -msingle-float doesn't work with double on O32 Sep 9, 2024
@yingopq yingopq force-pushed the Fix_bug_issue_93052 branch from e0bd6e8 to a5fd28e Compare September 10, 2024 08:07
@yingopq
Copy link
Contributor Author

yingopq commented Sep 10, 2024

Needs tests

OK, added.

@wzssyqa
Copy link
Contributor

wzssyqa commented Sep 10, 2024

No. This problem is about clang not llc.
The llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll is already OK.
Please see the bug report.

@wzssyqa wzssyqa self-requested a review September 10, 2024 16:04
@yingopq
Copy link
Contributor Author

yingopq commented Sep 11, 2024

No. This problem is about clang not llc. The llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll is already OK. Please see the bug report.

The lvm/test/CodeGen/Mips/2008-07-06-fadd64.ll file was discovered when I was looking for test cases that covered this problem reported.

This fix can resolve the bug reported, and when configured -mcpu=mips32r2 -mattr=single-float, llc and clang have same error info, debug information and issue reason. So I chose to improve this test case.

$ sudo ./build/bin/llc -march=mips -mcpu=mips32r2 -mattr=single-float -O2 < llvm/test/CodeGen/Mips/2008-07-06-fadd64.ll
	.text
	.abicalls
	.option	pic0
	.section	.mdebug.abi32,"",@progbits
	.nan	legacy
	.text
	.file	"<stdin>"
SoftenFloatOperand Op #0: t46: i32 = MipsISD::ExtractElementF64 t13, Constant:i32<1>

LLVM ERROR: Do not know how to soften this operator's operand!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: ./build/bin/llc -march=mips -mcpu=mips32r2 -mattr=single-float -O2
1.	Running pass 'Function Pass Manager' on module '<stdin>'.
2.	Running pass 'MIPS DAG->DAG Pattern Instruction Selection' on function '@dofloat'


// Skip the following function 'CustomLowerNode' when the operand had done
// `SoftenFloatResult`.
if (N->getOpcode() == ISD::BITCAST &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be special casing a specific opcode here, and shouldn't need to check the type of the actual softened result. It is also OK to request custom lowering on illegal types

@wzssyqa
Copy link
Contributor

wzssyqa commented Sep 12, 2024

Ohh. Thanks. Your patch fixes this problem.

And I will approve this PR once you fix the problem Matt found.
I guess he meant that you can just remove N->getOpcode() == ISD::BITCAST

@arsenm
Copy link
Contributor

arsenm commented Sep 12, 2024

Ohh. Thanks. Your patch fixes this problem.

And I will approve this PR once you fix the problem Matt found. I guess he meant that you can just remove N->getOpcode() == ISD::BITCAST

I mean the entire thing is suspect, you can request custom lowering on illegal types so CustomLowerNode should never be skipped

@yingopq
Copy link
Contributor Author

yingopq commented Sep 12, 2024

Ohh. Thanks. Your patch fixes this problem.
And I will approve this PR once you fix the problem Matt found. I guess he meant that you can just remove N->getOpcode() == ISD::BITCAST

I mean the entire thing is suspect, you can request custom lowering on illegal types so CustomLowerNode should never be skipped

OK, I would find another solution.

@yingopq yingopq force-pushed the Fix_bug_issue_93052 branch from a5fd28e to 741a80d Compare September 14, 2024 09:52
@yingopq
Copy link
Contributor Author

yingopq commented Sep 14, 2024

@wzssyqa I updated the code, please help review. Thanks!

@yingopq yingopq force-pushed the Fix_bug_issue_93052 branch from 741a80d to 94ba52d Compare September 18, 2024 09:09
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - cheers

Comment on lines 1 to 2
; 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need -O2. The mattr is also missing +, and -march should be mtriple

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, applied, thanks!

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

Fix llvm#93052
@yingopq yingopq force-pushed the Fix_bug_issue_93052 branch from 94ba52d to 822625f Compare September 19, 2024 02:42
@wzssyqa wzssyqa merged commit 72cacf1 into llvm:main Sep 19, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MIPS: -msingle-float doesn't work with double on O32
5 participants