Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit befab0a

Browse files
author
Reed Kotler
committed
Add fptrunc to mips fast-sel
Summary: Implement conversion of 64 to 32 bit floating point numbers (fptrunc) in mips fast-isel Test Plan: fptrunc.ll checked also with 4 internal mips build bot flavors mip32r1/miprs32r2 and at -O0 and -O2 Reviewers: dsanders Reviewed By: dsanders Subscribers: rfuhler Differential Revision: http://reviews.llvm.org/D5553 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218785 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 04d2186 commit befab0a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/Target/Mips/MipsFastISel.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class MipsFastISel final : public FastISel {
8181
bool SelectIntExt(const Instruction *I);
8282
bool SelectTrunc(const Instruction *I);
8383
bool SelectFPExt(const Instruction *I);
84+
bool SelectFPTrunc(const Instruction *I);
8485

8586
bool isTypeLegal(Type *Ty, MVT &VT);
8687
bool isLoadTypeLegal(Type *Ty, MVT &VT);
@@ -406,6 +407,28 @@ bool MipsFastISel::SelectFPExt(const Instruction *I) {
406407
return true;
407408
}
408409

410+
// Attempt to fast-select a floating-point truncate instruction.
411+
bool MipsFastISel::SelectFPTrunc(const Instruction *I) {
412+
Value *Src = I->getOperand(0);
413+
EVT SrcVT = TLI.getValueType(Src->getType(), true);
414+
EVT DestVT = TLI.getValueType(I->getType(), true);
415+
416+
if (SrcVT != MVT::f64 || DestVT != MVT::f32)
417+
return false;
418+
419+
unsigned SrcReg = getRegForValue(Src);
420+
if (!SrcReg)
421+
return false;
422+
423+
unsigned DestReg = createResultReg(&Mips::FGR32RegClass);
424+
if (!DestReg)
425+
return false;
426+
427+
EmitInst(Mips::CVT_S_D32, DestReg).addReg(SrcReg);
428+
updateValueMap(I, DestReg);
429+
return true;
430+
}
431+
409432
bool MipsFastISel::SelectIntExt(const Instruction *I) {
410433
Type *DestTy = I->getType();
411434
Value *Src = I->getOperand(0);
@@ -475,6 +498,8 @@ bool MipsFastISel::fastSelectInstruction(const Instruction *I) {
475498
case Instruction::ZExt:
476499
case Instruction::SExt:
477500
return SelectIntExt(I);
501+
case Instruction::FPTrunc:
502+
return SelectFPTrunc(I);
478503
case Instruction::FPExt:
479504
return SelectFPExt(I);
480505
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -march=mipsel -relocation-model=pic -O0 -mips-fast-isel -fast-isel-abort -mcpu=mips32r2 \
2+
; RUN: < %s | FileCheck %s
3+
; RUN: llc -march=mipsel -relocation-model=pic -O0 -mips-fast-isel -fast-isel-abort -mcpu=mips32 \
4+
; RUN: < %s | FileCheck %s
5+
6+
@d = global double 0x40147E6B74DF0446, align 8
7+
@f = common global float 0.000000e+00, align 4
8+
@.str = private unnamed_addr constant [6 x i8] c"%f \0A\00", align 1
9+
10+
; Function Attrs: nounwind
11+
define void @fv() #0 {
12+
entry:
13+
%0 = load double* @d, align 8
14+
%conv = fptrunc double %0 to float
15+
; CHECK: cvt.s.d $f{{[0-9]+}}, $f{{[0-9]+}}
16+
store float %conv, float* @f, align 4
17+
ret void
18+
}
19+
20+
attributes #1 = { nounwind }

0 commit comments

Comments
 (0)