Index: lib/Target/PowerPC/PPCISelLowering.cpp =================================================================== --- lib/Target/PowerPC/PPCISelLowering.cpp +++ lib/Target/PowerPC/PPCISelLowering.cpp @@ -6924,6 +6924,11 @@ SDValue PPCTargetLowering::LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, const SDLoc &dl) const { + + // FP to INT conversions are legal for f128. + if (EnableQuadPrecision && (Op->getOperand(0).getValueType() == MVT::f128)) + return Op; + // Expand ppcf128 to i32 by hand for the benefit of llvm-gcc bootstrap on // PPC (the libcall is not available). if (Op.getOperand(0).getValueType() == MVT::ppcf128) { 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 @@ -3132,7 +3136,7 @@ def : Pat<(f32 (fpround (f64 (extloadf32 ixaddr:$src)))), (f32 (DFLOADf32 ixaddr:$src))>; - // Convert (Un)Signed DWord in memory -> QP + // Convert (Un)Signed DWord in memory -> QP. def : Pat<(f128 (sint_to_fp (i64 (load xaddr:$src)))), (f128 (XSCVSDQP (LXSDX xaddr:$src)))>; def : Pat<(f128 (sint_to_fp (i64 (load ixaddr:$src)))), @@ -3150,6 +3154,16 @@ 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)), ixaddr:$dst), + (STXSD (COPY_TO_REGCLASS (XSCVQPSDZ $src), VFRC), ixaddr:$dst)>; + def : Pat<(store (i64 (fp_to_sint f128:$src)), xaddr:$dst), + (STXSDX (COPY_TO_REGCLASS (XSCVQPSDZ $src), VFRC), xaddr:$dst)>; + def : Pat<(store (i64 (fp_to_uint f128:$src)), ixaddr:$dst), + (STXSD (COPY_TO_REGCLASS (XSCVQPUDZ $src), VFRC), ixaddr:$dst)>; + def : Pat<(store (i64 (fp_to_uint f128:$src)), xaddr:$dst), + (STXSDX (COPY_TO_REGCLASS (XSCVQPUDZ $src), VFRC), xaddr:$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,195 @@ +; RUN: llc -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown \ +; RUN: -verify-machineinstrs -enable-ppc-quad-precision \ +; RUN: -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 [[CONV:[0-9]+]], [[REG]] +; CHECK-NEXT: mfvsrd 3, [[CONV]] +; 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 [[CONV:[0-9]+]], [[REG]] +; CHECK-NEXT: stxsd [[CONV]], 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 [[CONV:[0-9]+]], [[REG]] +; CHECK-NEXT: mfvsrd 3, [[CONV]] +; 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 [[CONV:[0-9]+]], [[REG]] +; CHECK-NEXT: stxsd [[CONV]], 0(5) +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind +define void @qpConv2sdw_testXForm(i64* nocapture %res, i32 signext %idx) { +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 + %idxprom = sext i32 %idx to i64 + %arrayidx = getelementptr inbounds i64, i64* %res, i64 %idxprom + store i64 %conv, i64* %arrayidx, align 8 + ret void + +; CHECK-LABEL: qpConv2sdw_testXForm +; CHECK: xscvqpsdz [[CONV:[0-9]+]], +; CHECK-NEXT: stxsdx [[CONV]], 3, 4 +; 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 [[CONV:[0-9]+]], [[REG]] +; CHECK-NEXT: mfvsrd 3, [[CONV]] +; 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 [[CONV:[0-9]+]], [[REG]] +; CHECK-NEXT: stxsd [[CONV]], 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 [[CONV:[0-9]+]], [[REG]] +; CHECK-NEXT: mfvsrd 3, [[CONV]] +; 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 [[CONV:[0-9]+]], [[REG]] +; CHECK-NEXT: stxsd [[CONV]], 0(5) +; CHECK-NEXT: blr +} + +; Function Attrs: norecurse nounwind +define void @qpConv2udw_testXForm(i64* nocapture %res, i32 signext %idx) { +entry: + %0 = load fp128, fp128* getelementptr inbounds + ([4 x fp128], [4 x fp128]* @f128Array, + i64 0, i64 0), align 16 + %conv = fptoui fp128 %0 to i64 + %idxprom = sext i32 %idx to i64 + %arrayidx = getelementptr inbounds i64, i64* %res, i64 %idxprom + store i64 %conv, i64* %arrayidx, align 8 + ret void + +; CHECK-LABEL: qpConv2udw_testXForm +; CHECK: xscvqpudz [[CONV:[0-9]+]], +; CHECK-NEXT: stxsdx [[CONV]], 3, 4 +; CHECK-NEXT: blr +}