Index: lib/Target/PowerPC/PPCISelLowering.cpp =================================================================== --- lib/Target/PowerPC/PPCISelLowering.cpp +++ lib/Target/PowerPC/PPCISelLowering.cpp @@ -9406,8 +9406,11 @@ case ISD::TRUNCATE: return LowerTRUNCATE(Op, DAG); case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); case ISD::FP_TO_UINT: - case ISD::FP_TO_SINT: return LowerFP_TO_INT(Op, DAG, - SDLoc(Op)); + case ISD::FP_TO_SINT: + // Legalize instruction for converting f128 to integer types + if (EnableQuadPrecision && (Op->getOperand(0).getValueType() == MVT::f128)) + return Op; + return LowerFP_TO_INT(Op, DAG, SDLoc(Op)); case ISD::UINT_TO_FP: case ISD::SINT_TO_FP: // Legalize instruction for f128 result type Index: lib/Target/PowerPC/PPCInstrVSX.td =================================================================== --- lib/Target/PowerPC/PPCInstrVSX.td +++ lib/Target/PowerPC/PPCInstrVSX.td @@ -2506,8 +2506,12 @@ // Truncate & Convert QP -> (Un)Signed (D)Word (dword[1] is set to zero) def XSCVQPSDZ : X_VT5_XO5_VB5<63, 25, 836, "xscvqpsdz", []>; + def : Pat<(i64 (fp_to_sint f128:$src)), + (i64 (MFVRD (XSCVQPSDZ $src)))>; def XSCVQPSWZ : X_VT5_XO5_VB5<63, 9, 836, "xscvqpswz", []>; def XSCVQPUDZ : X_VT5_XO5_VB5<63, 17, 836, "xscvqpudz", []>; + def : Pat<(i64 (fp_to_uint f128:$src)), + (i64 (MFVRD (XSCVQPUDZ $src)))>; def XSCVQPUWZ : X_VT5_XO5_VB5<63, 1, 836, "xscvqpuwz", []>; // Convert (Un)Signed DWord -> QP @@ -3146,6 +3150,12 @@ def : Pat<(f128 (uint_to_fp ScalarLoads.ZELi8)), (f128 (XSCVUDQP (LXSIBZX xoaddr:$src)))>; + // Truncate & Convert QP -> (Un)Signed DWord in memory + def : Pat<(store (i64 (fp_to_sint f128:$src)), xoaddr:$dst), + (STXSD (COPY_TO_REGCLASS (XSCVQPSDZ $src), VFRC), xoaddr:$dst)>; + def : Pat<(store (i64 (fp_to_uint f128:$src)), xoaddr:$dst), + (STXSD (COPY_TO_REGCLASS (XSCVQPUDZ $src), VFRC), xoaddr:$dst)>; + } // end HasP9Vector, AddedComplexity let Predicates = [HasP9Vector] in { Index: test/CodeGen/PowerPC/f128-truncateNconv.ll =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/f128-truncateNconv.ll @@ -0,0 +1,158 @@ +; RUN: llc -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown \ +; RUN: -enable-ppc-quad-precision -ppc-vsr-nums-as-vr < %s | FileCheck %s + +@f128Array = global [4 x fp128] [fp128 0xL00000000000000004004C00000000000, + fp128 0xLF000000000000000400808AB851EB851, + fp128 0xL5000000000000000400E0C26324C8366, + fp128 0xL8000000000000000400A24E2E147AE14], + align 16 + +; Function Attrs: norecurse nounwind readonly +define i64 @qpConv2sdw(fp128* nocapture readonly %a) { +entry: + %0 = load fp128, fp128* %a, align 16 + %conv = fptosi fp128 %0 to i64 + ret i64 %conv + +; CHECK-LABEL: qpConv2sdw +; CHECK: lxv [[REG:[0-9]+]], 0(3) +; CHECK-NEXT: xscvqpsdz [[REG]], [[REG]] +; CHECK-NEXT: mfvsrd 3, [[REG]] +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind +define void @qpConv2sdw_02(i64* nocapture %res) local_unnamed_addr #1 { +entry: + %0 = load fp128, fp128* getelementptr inbounds + ([4 x fp128], [4 x fp128]* @f128Array, i64 0, + i64 2), align 16 + %conv = fptosi fp128 %0 to i64 + store i64 %conv, i64* %res, align 8 + ret void + +; CHECK-LABEL: qpConv2sdw_02 +; CHECK: addis [[REG0:[0-9]+]], 2, .LC0@toc@ha +; CHECK: ld [[REG0]], .LC0@toc@l([[REG0]]) +; CHECK: lxv [[REG:[0-9]+]], 32([[REG0]]) +; CHECK-NEXT: xscvqpsdz [[REG]], [[REG]] +; CHECK-NEXT: stxsd [[REG]], 0(3) +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind readonly +define i64 @qpConv2sdw_03(fp128* nocapture readonly %a) { +entry: + %0 = load fp128, fp128* %a, align 16 + %1 = load fp128, fp128* getelementptr inbounds + ([4 x fp128], [4 x fp128]* @f128Array, i64 0, + i64 1), align 16 + %add = fadd fp128 %0, %1 + %conv = fptosi fp128 %add to i64 + ret i64 %conv + +; CHECK-LABEL: qpConv2sdw_03 +; CHECK: addis [[REG0:[0-9]+]], 2, .LC0@toc@ha +; CHECK-DAG: ld [[REG0]], .LC0@toc@l([[REG0]]) +; CHECK-DAG: lxv [[REG1:[0-9]+]], 16([[REG0]]) +; CHECK-DAG: lxv [[REG:[0-9]+]], 0(3) +; CHECK: xsaddqp [[REG]], [[REG]], [[REG1]] +; CHECK-NEXT: xscvqpsdz [[REG]], [[REG]] +; CHECK-NEXT: mfvsrd 3, [[REG]] +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind +define void @qpConv2sdw_04(fp128* nocapture readonly %a, + fp128* nocapture readonly %b, i64* nocapture %res) { +entry: + %0 = load fp128, fp128* %a, align 16 + %1 = load fp128, fp128* %b, align 16 + %add = fadd fp128 %0, %1 + %conv = fptosi fp128 %add to i64 + store i64 %conv, i64* %res, align 8 + ret void + +; CHECK-LABEL: qpConv2sdw_04 +; CHECK-DAG: lxv [[REG1:[0-9]+]], 0(4) +; CHECK-DAG: lxv [[REG:[0-9]+]], 0(3) +; CHECK: xsaddqp [[REG]], [[REG]], [[REG1]] +; CHECK-NEXT: xscvqpsdz [[REG]], [[REG]] +; CHECK-NEXT: stxsd [[REG]], 0(5) +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind readonly +define i64 @qpConv2udw(fp128* nocapture readonly %a) { +entry: + %0 = load fp128, fp128* %a, align 16 + %conv = fptoui fp128 %0 to i64 + ret i64 %conv + +; CHECK-LABEL: qpConv2udw +; CHECK: lxv [[REG:[0-9]+]], 0(3) +; CHECK-NEXT: xscvqpudz [[REG]], [[REG]] +; CHECK-NEXT: mfvsrd 3, [[REG]] +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind +define void @qpConv2udw_02(i64* nocapture %res) { +entry: + %0 = load fp128, fp128* getelementptr inbounds + ([4 x fp128], [4 x fp128]* @f128Array, i64 0, + i64 2), align 16 + %conv = fptoui fp128 %0 to i64 + store i64 %conv, i64* %res, align 8 + ret void + +; CHECK-LABEL: qpConv2udw_02 +; CHECK: addis [[REG0:[0-9]+]], 2, .LC0@toc@ha +; CHECK: ld [[REG0]], .LC0@toc@l([[REG0]]) +; CHECK: lxv [[REG:[0-9]+]], 32([[REG0]]) +; CHECK-NEXT: xscvqpudz [[REG]], [[REG]] +; CHECK-NEXT: stxsd [[REG]], 0(3) +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind readonly +define i64 @qpConv2udw_03(fp128* nocapture readonly %a) { +entry: + %0 = load fp128, fp128* %a, align 16 + %1 = load fp128, fp128* getelementptr inbounds + ([4 x fp128], [4 x fp128]* @f128Array, i64 0, + i64 1), align 16 + %add = fadd fp128 %0, %1 + %conv = fptoui fp128 %add to i64 + ret i64 %conv + +; CHECK-LABEL: qpConv2udw_03 +; CHECK: addis [[REG0:[0-9]+]], 2, .LC0@toc@ha +; CHECK-DAG: ld [[REG0]], .LC0@toc@l([[REG0]]) +; CHECK-DAG: lxv [[REG1:[0-9]+]], 16([[REG0]]) +; CHECK-DAG: lxv [[REG:[0-9]+]], 0(3) +; CHECK: xsaddqp [[REG]], [[REG]], [[REG1]] +; CHECK-NEXT: xscvqpudz [[REG]], [[REG]] +; CHECK-NEXT: mfvsrd 3, [[REG]] +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind +define void @qpConv2udw_04(fp128* nocapture readonly %a, + fp128* nocapture readonly %b, i64* nocapture %res) { +entry: + %0 = load fp128, fp128* %a, align 16 + %1 = load fp128, fp128* %b, align 16 + %add = fadd fp128 %0, %1 + %conv = fptoui fp128 %add to i64 + store i64 %conv, i64* %res, align 8 + ret void + +; CHECK-LABEL: qpConv2udw_04 +; CHECK-DAG: lxv [[REG1:[0-9]+]], 0(4) +; CHECK-DAG: lxv [[REG:[0-9]+]], 0(3) +; CHECK: xsaddqp [[REG]], [[REG]], [[REG1]] +; CHECK-NEXT: xscvqpudz [[REG]], [[REG]] +; CHECK-NEXT: stxsd [[REG]], 0(5) +; CHECK-NEXT: blr +}