Skip to content

Commit ab348bc

Browse files
committed
address comments
1 parent cfbce1a commit ab348bc

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
13801380
// After all vararg is processed, 'VAOffset' holds the size of the
13811381
// vararg byte array.
13821382

1383-
SDValue VADeclareParam; // vararg byte array
1383+
SDValue VADeclareParam = SDValue(); // vararg byte array
13841384
const unsigned FirstVAArg = CLI.NumFixedArgs; // position of first variadic
13851385
unsigned VAOffset = 0; // current offset in the param array
13861386

@@ -1583,8 +1583,6 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
15831583
VAOffset += TypeSize;
15841584
}
15851585

1586-
GlobalAddressSDNode *Func = dyn_cast<GlobalAddressSDNode>(Callee.getNode());
1587-
15881586
// Handle Result
15891587
if (!Ins.empty()) {
15901588
const SDValue RetSymbol = DAG.getExternalSymbol("retval0", MVT::i32);
@@ -1597,10 +1595,9 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
15971595
}
15981596
}
15991597

1600-
const bool HasVAArgs = CLI.IsVarArg && (CLI.Args.size() > CLI.NumFixedArgs);
16011598
// Set the size of the vararg param byte array if the callee is a variadic
16021599
// function and the variadic part is not empty.
1603-
if (HasVAArgs) {
1600+
if (VADeclareParam) {
16041601
SDValue DeclareParamOps[] = {VADeclareParam.getOperand(0),
16051602
VADeclareParam.getOperand(1),
16061603
VADeclareParam.getOperand(2), GetI32(VAOffset),
@@ -1609,6 +1606,7 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
16091606
VADeclareParam->getVTList(), DeclareParamOps);
16101607
}
16111608

1609+
const auto *Func = dyn_cast<GlobalAddressSDNode>(Callee.getNode());
16121610
// If the type of the callsite does not match that of the function, convert
16131611
// the callsite to an indirect call.
16141612
const bool ConvertToIndirectCall = shouldConvertToIndirectCall(CB, Func);
@@ -1638,6 +1636,7 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
16381636
// instruction.
16391637
// The prototype is embedded in a string and put as the operand for a
16401638
// CallPrototype SDNode which will print out to the value of the string.
1639+
const bool HasVAArgs = CLI.IsVarArg && (CLI.Args.size() > CLI.NumFixedArgs);
16411640
std::string Proto =
16421641
getPrototype(DL, RetTy, Args, CLI.Outs,
16431642
HasVAArgs ? std::optional(FirstVAArg) : std::nullopt, *CB,
@@ -5540,6 +5539,15 @@ static SDValue combineADDRSPACECAST(SDNode *N,
55405539
return SDValue();
55415540
}
55425541

5542+
// During call lowering we wrap the return values in a ProxyReg node which depend
5543+
// on the chain value produced by the completed call. This ensures that the
5544+
// full call is emitted in cases where libcalls are used to legalize operations.
5545+
// To improve the functioning of other DAG combines we pull all operations we
5546+
// can through one of these nodes, ensuring that the ProxyReg directly wraps a
5547+
// load. That is:
5548+
//
5549+
// (ProxyReg (zext (load retval0))) => (zext (ProxyReg (load retval0)))
5550+
//
55435551
static SDValue sinkProxyReg(SDValue R, SDValue Chain,
55445552
TargetLowering::DAGCombinerInfo &DCI) {
55455553
switch (R.getOpcode()) {
@@ -5593,6 +5601,8 @@ static SDValue combineProxyReg(SDNode *N,
55935601
SDValue Chain = N->getOperand(0);
55945602
SDValue Reg = N->getOperand(1);
55955603

5604+
// If the ProxyReg is not wrapping a load, try to pull the operations through
5605+
// the ProxyReg.
55965606
if (Reg.getOpcode() != ISD::LOAD) {
55975607
if (SDValue V = sinkProxyReg(Reg, Chain, DCI))
55985608
return V;

0 commit comments

Comments
 (0)