Subzero, MIPS32: Handling fptrunc and fpext casting

Patch implements truncation and extension of FP values.

R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/2324903002 .

Patch from Srdjan Obucina <Srdjan.Obucina@imgtec.com>.
diff --git a/src/IceTargetLoweringMIPS32.cpp b/src/IceTargetLoweringMIPS32.cpp
index 19a054b..622af79 100644
--- a/src/IceTargetLoweringMIPS32.cpp
+++ b/src/IceTargetLoweringMIPS32.cpp
@@ -2393,22 +2393,31 @@
     _mov(Dest, T);
     break;
   }
-  case InstCast::Fptrunc:
-    // Use _cvt_d_s
-    UnimplementedLoweringError(this, Instr);
-    break;
-  case InstCast::Fpext: {
-    // Use _cvt_s_d
-    UnimplementedLoweringError(this, Instr);
+  case InstCast::Fptrunc: {
+    assert(Dest->getType() == IceType_f32);
+    assert(Src0->getType() == IceType_f64);
+    auto *DestR = legalizeToReg(Dest);
+    auto *Src0R = legalizeToReg(Src0);
+    _cvt_s_d(DestR, Src0R);
+    _mov(Dest, DestR);
     break;
   }
-  case InstCast::Fptosi:
+  case InstCast::Fpext: {
+    assert(Dest->getType() == IceType_f64);
+    assert(Src0->getType() == IceType_f32);
+    auto *DestR = legalizeToReg(Dest);
+    auto *Src0R = legalizeToReg(Src0);
+    _cvt_d_s(DestR, Src0R);
+    _mov(Dest, DestR);
+    break;
+  }
+  case InstCast::Fptosi: //
     UnimplementedLoweringError(this, Instr);
     break;
   case InstCast::Fptoui:
     UnimplementedLoweringError(this, Instr);
     break;
-  case InstCast::Sitofp:
+  case InstCast::Sitofp: //
     UnimplementedLoweringError(this, Instr);
     break;
   case InstCast::Uitofp: {
diff --git a/tests_lit/llvm2ice_tests/fp.convert.ll b/tests_lit/llvm2ice_tests/fp.convert.ll
index 4fc71f8..d1bd743 100644
--- a/tests_lit/llvm2ice_tests/fp.convert.ll
+++ b/tests_lit/llvm2ice_tests/fp.convert.ll
@@ -16,6 +16,11 @@
 ; RUN:   | %if --need=allow_dump --need=target_ARM32 --command FileCheck %s \
 ; RUN:   --check-prefix=ARM32
 
+; RUN: %if --need=allow_dump --need=target_MIPS32 --command %p2i \
+; RUN:   --filetype=asm --target mips32 -i %s --args -Om1 --skip-unimplemented \
+; RUN:   | %if --need=allow_dump --need=target_MIPS32 --command FileCheck %s \
+; RUN:   --check-prefix=MIPS32
+
 define internal float @fptrunc(double %a) {
 entry:
   %conv = fptrunc double %a to float
@@ -26,6 +31,8 @@
 ; CHECK: fld
 ; ARM32-LABEL: fptrunc
 ; ARM32: vcvt.f32.f64 {{s[0-9]+}}, {{d[0-9]+}}
+; MIPS32-LABEL: fptrunc
+; MIPS32: cvt.s.d
 
 define internal double @fpext(float %a) {
 entry:
@@ -37,6 +44,8 @@
 ; CHECK: fld
 ; ARM32-LABEL: fpext
 ; ARM32: vcvt.f64.f32 {{d[0-9]+}}, {{s[0-9]+}}
+; MIPS32-LABEL: fpext
+; MIPS32: cvt.d.s
 
 define internal i64 @doubleToSigned64(double %a) {
 entry: