Index: llvm/include/llvm/CodeGen/TargetLowering.h =================================================================== --- llvm/include/llvm/CodeGen/TargetLowering.h +++ llvm/include/llvm/CodeGen/TargetLowering.h @@ -3008,10 +3008,13 @@ MakeLibCallOptions CallOptions, const SDLoc &dl) const; + // FIXME: Merge with makeLibCall? std::pair ExpandChainLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, - SDNode *Node, - bool isSigned) const; + EVT RetVT, + ArrayRef Ops, + bool isSigned, + const SDLoc &dl) const; /// Check whether parameters to a call that are passed in callee saved /// registers are the same as from the calling function. This needs to be Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -2098,9 +2098,12 @@ } if (Node->isStrictFPOpcode()) { + EVT RetVT = Node->getValueType(0); + SmallVector Ops(Node->op_begin(), Node->op_end()); // FIXME: This doesn't support tail calls. - std::pair Tmp = TLI.ExpandChainLibCall(DAG, LC, Node, - false); + std::pair Tmp = TLI.ExpandChainLibCall(DAG, LC, RetVT, + Ops, false, + SDLoc(Node)); Results.push_back(Tmp.first); Results.push_back(Tmp.second); } else { @@ -2149,9 +2152,12 @@ } if (Node->isStrictFPOpcode()) { + EVT RetVT = Node->getValueType(0); + SmallVector Ops(Node->op_begin(), Node->op_end()); // FIXME: This doesn't support tail calls. - std::pair Tmp = TLI.ExpandChainLibCall(DAG, LC, Node, - false); + std::pair Tmp = TLI.ExpandChainLibCall(DAG, LC, RetVT, + Ops, false, + SDLoc(Node)); Results.push_back(Tmp.first); Results.push_back(Tmp.second); } else { @@ -3786,8 +3792,11 @@ RTLIB::Libcall LC = RTLIB::getSYNC(Opc, VT); assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected atomic op or value type!"); - std::pair Tmp = TLI.ExpandChainLibCall(DAG, LC, Node, - false); + EVT RetVT = Node->getValueType(0); + SmallVector Ops(Node->op_begin(), Node->op_end()); + std::pair Tmp = TLI.ExpandChainLibCall(DAG, LC, RetVT, + Ops, false, + SDLoc(Node)); Results.push_back(Tmp.first); Results.push_back(Tmp.second); break; Index: llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -1818,7 +1818,9 @@ RTLIB::Libcall LC = RTLIB::getSYNC(Opc, VT); assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected atomic op or value type!"); - return TLI.ExpandChainLibCall(DAG, LC, Node, false); + EVT RetVT = Node->getValueType(0); + SmallVector Ops(Node->op_begin(), Node->op_end()); + return TLI.ExpandChainLibCall(DAG, LC, RetVT, Ops, false, SDLoc(Node)); } /// N is a shift by a value that needs to be expanded, @@ -2629,7 +2631,9 @@ EVT RetVT = N->getValueType(0); if (N->isStrictFPOpcode()) { - std::pair Tmp = TLI.ExpandChainLibCall(DAG, LC, N, true); + SDValue Ops[] = { N->getOperand(0), Op }; + std::pair Tmp = TLI.ExpandChainLibCall(DAG, LC, RetVT, + Ops, true, dl); SplitInteger(Tmp.first, Lo, Hi); ReplaceValueWith(SDValue(N, 1), Tmp.second); return; Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -172,15 +172,16 @@ /// the first operand is the in-chain. std::pair TargetLowering::ExpandChainLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, - SDNode *Node, bool isSigned) const { - SDValue InChain = Node->getOperand(0); + EVT RetVT, ArrayRef Ops, + bool isSigned, const SDLoc &dl) const { + SDValue InChain = Ops[0]; TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; - for (unsigned i = 1, e = Node->getNumOperands(); i != e; ++i) { - EVT ArgVT = Node->getOperand(i).getValueType(); + for (unsigned i = 1, e = Ops.size(); i != e; ++i) { + EVT ArgVT = Ops[i].getValueType(); Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext()); - Entry.Node = Node->getOperand(i); + Entry.Node = Ops[i]; Entry.Ty = ArgTy; Entry.IsSExt = isSigned; Entry.IsZExt = !isSigned; @@ -189,10 +190,10 @@ SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC), getPointerTy(DAG.getDataLayout())); - Type *RetTy = Node->getValueType(0).getTypeForEVT(*DAG.getContext()); + Type *RetTy = RetVT.getTypeForEVT(*DAG.getContext()); TargetLowering::CallLoweringInfo CLI(DAG); - CLI.setDebugLoc(SDLoc(Node)) + CLI.setDebugLoc(dl) .setChain(InChain) .setLibCallee(getLibcallCallingConv(LC), RetTy, Callee, std::move(Args))