Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -7314,7 +7314,10 @@ if (((N0.getOpcode() == ISD::FNEG && !TLI.isFNegFree(N0.getValueType())) || (N0.getOpcode() == ISD::FABS && !TLI.isFAbsFree(N0.getValueType()))) && N0.getNode()->hasOneUse() && VT.isInteger() && - !VT.isVector() && !N0.getValueType().isVector()) { + // ppcf128 uses two doubles; the signbit should be calculated in other + // ways. + N0.getValueType() != MVT::ppcf128 && !VT.isVector() && + !N0.getValueType().isVector()) { SDValue NewConv = DAG.getNode(ISD::BITCAST, SDLoc(N0), VT, N0.getOperand(0)); AddToWorklist(NewConv.getNode()); @@ -7335,7 +7338,11 @@ // folded to an fneg or fabs. if (N0.getOpcode() == ISD::FCOPYSIGN && N0.getNode()->hasOneUse() && isa(N0.getOperand(0)) && - VT.isInteger() && !VT.isVector()) { + // ppcf128 uses two doubles; the signbit should be calculated in other + // ways. + N0.getOperand(0).getValueType() != MVT::ppcf128 && + N0.getOperand(1).getValueType() != MVT::ppcf128 && VT.isInteger() && + !VT.isVector()) { unsigned OrigXWidth = N0.getOperand(1).getValueType().getSizeInBits(); EVT IntXVT = EVT::getIntegerVT(*DAG.getContext(), OrigXWidth); if (isTypeLegal(IntXVT)) { Index: test/CodeGen/PowerPC/fp128-bitcast-after-operation.ll =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/fp128-bitcast-after-operation.ll @@ -0,0 +1,26 @@ +; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s + +define ppc_fp128 @test_abs(ppc_fp128 %x) nounwind { +entry: +; CHECK: xsabsdp 1 +; CHECK-NEXT: xscmpudp [[REG:[0-9]+]] +; CHECK-NEXT: beqlr [[REG]] +; CHECK-NEXT: xsnegdp 2 + %tmp2 = tail call ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %x) + ret ppc_fp128 %tmp2 +} + +define i128 @test_copysign(ppc_fp128 %x) nounwind { +entry: +; CHECK: stxsdx 1, 0, [[REG1:[0-9]+]] +; CHECK: stxsdx 2, 0, [[REG2:[0-9]+]] +; CHECK: bl copysignl +; CHECK: ld [[REG1]], 96(1) +; CHECK: ld [[REG2]], 104(1) + %tmp2 = tail call ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 0xM3FF00000000000000000000000000000, ppc_fp128 %x) + %tmp3 = bitcast ppc_fp128 %tmp2 to i128 + ret i128 %tmp3 +} + +declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128) +declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128, ppc_fp128)