Skip to content

Commit

Permalink
[PowerPC] Legalize rounding nodes
Browse files Browse the repository at this point in the history
VSX provides a full complement of rounding instructions yet we somehow ended up
with some of them legal and others not. This just legalizes all of the FP
rounding nodes and the FP -> int rounding nodes with unsafe math.

Differential revision: https://reviews.llvm.org/D69949
  • Loading branch information
nemanjai committed Dec 30, 2019
1 parent 32cc141 commit 0f0330a
Show file tree
Hide file tree
Showing 6 changed files with 717 additions and 278 deletions.
15 changes: 15 additions & 0 deletions llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Expand Up @@ -390,6 +390,16 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
setOperationAction(ISD::BITCAST, MVT::i32, Legal);
setOperationAction(ISD::BITCAST, MVT::i64, Legal);
setOperationAction(ISD::BITCAST, MVT::f64, Legal);
if (TM.Options.UnsafeFPMath) {
setOperationAction(ISD::LRINT, MVT::f64, Legal);
setOperationAction(ISD::LRINT, MVT::f32, Legal);
setOperationAction(ISD::LLRINT, MVT::f64, Legal);
setOperationAction(ISD::LLRINT, MVT::f32, Legal);
setOperationAction(ISD::LROUND, MVT::f64, Legal);
setOperationAction(ISD::LROUND, MVT::f32, Legal);
setOperationAction(ISD::LLROUND, MVT::f64, Legal);
setOperationAction(ISD::LLROUND, MVT::f32, Legal);
}
} else {
setOperationAction(ISD::BITCAST, MVT::f32, Expand);
setOperationAction(ISD::BITCAST, MVT::i32, Expand);
Expand Down Expand Up @@ -777,8 +787,13 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
setOperationAction(ISD::FTRUNC, MVT::v2f64, Legal);
setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Legal);
setOperationAction(ISD::FROUND, MVT::v2f64, Legal);
setOperationAction(ISD::FNEARBYINT, MVT::f64, Legal);
setOperationAction(ISD::FROUND, MVT::f64, Legal);

setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Legal);
setOperationAction(ISD::FROUND, MVT::v4f32, Legal);
setOperationAction(ISD::FNEARBYINT, MVT::f32, Legal);
setOperationAction(ISD::FROUND, MVT::f32, Legal);

setOperationAction(ISD::MUL, MVT::v2f64, Legal);
setOperationAction(ISD::FMA, MVT::v2f64, Legal);
Expand Down
37 changes: 37 additions & 0 deletions llvm/lib/Target/PowerPC/PPCInstrVSX.td
Expand Up @@ -2526,6 +2526,43 @@ def : Pat<(i64 (bitconvert f64:$S)),
// (move to FPR, nothing else needed)
def : Pat<(f64 (bitconvert i64:$S)),
(f64 (MTVSRD $S))>;

// Rounding to integer.
def : Pat<(i64 (lrint f64:$S)),
(i64 (MFVSRD (FCTID $S)))>;
def : Pat<(i64 (lrint f32:$S)),
(i64 (MFVSRD (FCTID (COPY_TO_REGCLASS $S, F8RC))))>;
def : Pat<(i64 (llrint f64:$S)),
(i64 (MFVSRD (FCTID $S)))>;
def : Pat<(i64 (llrint f32:$S)),
(i64 (MFVSRD (FCTID (COPY_TO_REGCLASS $S, F8RC))))>;
def : Pat<(i64 (lround f64:$S)),
(i64 (MFVSRD (FCTID (XSRDPI $S))))>;
def : Pat<(i64 (lround f32:$S)),
(i64 (MFVSRD (FCTID (XSRDPI (COPY_TO_REGCLASS $S, VSFRC)))))>;
def : Pat<(i64 (llround f64:$S)),
(i64 (MFVSRD (FCTID (XSRDPI $S))))>;
def : Pat<(i64 (llround f32:$S)),
(i64 (MFVSRD (FCTID (XSRDPI (COPY_TO_REGCLASS $S, VSFRC)))))>;
}

let Predicates = [HasVSX] in {
// Rounding for single precision.
def : Pat<(f32 (fround f32:$S)),
(f32 (COPY_TO_REGCLASS (XSRDPI
(COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
def : Pat<(f32 (fnearbyint f32:$S)),
(f32 (COPY_TO_REGCLASS (XSRDPIC
(COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
def : Pat<(f32 (ffloor f32:$S)),
(f32 (COPY_TO_REGCLASS (XSRDPIM
(COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
def : Pat<(f32 (fceil f32:$S)),
(f32 (COPY_TO_REGCLASS (XSRDPIP
(COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
def : Pat<(f32 (ftrunc f32:$S)),
(f32 (COPY_TO_REGCLASS (XSRDPIZ
(COPY_TO_REGCLASS $S, VSFRC)), VSSRC))>;
}

// Materialize a zero-vector of long long
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/fp-int128-fp-combine.ll
Expand Up @@ -29,7 +29,7 @@ entry:
define float @f_i128_fi_nsz(float %v) #0 {
; CHECK-LABEL: f_i128_fi_nsz:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: friz 0, 1
; CHECK-NEXT: xsrdpiz 0, 1
; CHECK-NEXT: fmr 1, 0
; CHECK-NEXT: blr
entry:
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/CodeGen/PowerPC/rounding-ops.ll
Expand Up @@ -10,7 +10,7 @@ define float @test1(float %x) nounwind {
; CHECK-LABEL: test1:
; CHECK: frim 1, 1
; CHECK-VSX-LABEL: test1:
; CHECK-VSX: frim 1, 1
; CHECK-VSX: xsrdpim 1, 1
}

declare float @floorf(float) nounwind readnone
Expand All @@ -34,7 +34,7 @@ define float @test3(float %x) nounwind {
; CHECK-LABEL: test3:
; CHECK: frin 1, 1
; CHECK-VSX-LABEL: test3:
; CHECK-VSX: frin 1, 1
; CHECK-VSX: xsrdpi 1, 1
}

declare float @roundf(float) nounwind readnone
Expand All @@ -58,7 +58,7 @@ define float @test5(float %x) nounwind {
; CHECK-LABEL: test5:
; CHECK: frip 1, 1
; CHECK-VSX-LABEL: test5:
; CHECK-VSX: frip 1, 1
; CHECK-VSX: xsrdpip 1, 1
}

declare float @ceilf(float) nounwind readnone
Expand All @@ -82,7 +82,7 @@ define float @test9(float %x) nounwind {
; CHECK-LABEL: test9:
; CHECK: friz 1, 1
; CHECK-VSX-LABEL: test9:
; CHECK-VSX: friz 1, 1
; CHECK-VSX: xsrdpiz 1, 1
}

declare float @truncf(float) nounwind readnone
Expand Down

0 comments on commit 0f0330a

Please sign in to comment.