[llvm] [Mips] Add r5900 (PlayStation 2 Emotion Engine) FPU Support (PR #178942)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 7 03:59:18 PST 2026


================
@@ -0,0 +1,210 @@
+; RUN: llc -mtriple=mips64el -mcpu=r5900 < %s | FileCheck %s
+;
+; Test that R5900 FPU comparisons only generate supported instructions.
+; R5900 only supports: C.F (0x30), C.EQ (0x32), C.OLT (0x34), C.OLE (0x36)
+;
+; Unsupported conditions are transformed:
+; - Unordered (ULT, ULE, UEQ, etc.) → Ordered equivalents (R5900 has no NaN)
+; - Greater-than → Less-than with swapped operands
+
+;-----------------------------------------------------------------------------
+; Ordered comparisons
+;-----------------------------------------------------------------------------
+
+define i32 @test_oeq(float %a, float %b) {
+; CHECK-LABEL: test_oeq:
+; CHECK: c.eq.s $f12, $f13
+; CHECK-NOT: c.ueq
+  %cmp = fcmp oeq float %a, %b
+  %result = zext i1 %cmp to i32
+  ret i32 %result
+}
+
+define i32 @test_olt(float %a, float %b) {
+; CHECK-LABEL: test_olt:
+; CHECK: c.olt.s $f12, $f13
+; CHECK-NOT: c.ult
+  %cmp = fcmp olt float %a, %b
+  %result = zext i1 %cmp to i32
+  ret i32 %result
+}
+
+define i32 @test_ole(float %a, float %b) {
+; CHECK-LABEL: test_ole:
+; CHECK: c.ole.s $f12, $f13
+; CHECK-NOT: c.ule
+  %cmp = fcmp ole float %a, %b
+  %result = zext i1 %cmp to i32
+  ret i32 %result
+}
+
+define i32 @test_ogt(float %a, float %b) {
+; CHECK-LABEL: test_ogt:
+; CHECK: c.olt.s $f13, $f12
+; Swapped operands: a > b  →  b < a
+  %cmp = fcmp ogt float %a, %b
+  %result = zext i1 %cmp to i32
+  ret i32 %result
+}
+
+define i32 @test_oge(float %a, float %b) {
+; CHECK-LABEL: test_oge:
+; CHECK: c.ole.s $f13, $f12
+; Swapped operands: a >= b  →  b <= a
+  %cmp = fcmp oge float %a, %b
+  %result = zext i1 %cmp to i32
+  ret i32 %result
+}
+
+;-----------------------------------------------------------------------------
+; Unordered comparisons - mapped to ordered (R5900 FPU has no NaN)
----------------
arsenm wrote:

This is incorrect handling. You can't disregard the semantics of the IR instruction because the instruction doesn't handle it correctly. 

https://github.com/llvm/llvm-project/pull/178942


More information about the llvm-commits mailing list