Skip to content

Commit d31bc98

Browse files
committed
address comments
1 parent e6de86f commit d31bc98

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
@@ -1402,7 +1402,7 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
14021402
// After all vararg is processed, 'VAOffset' holds the size of the
14031403
// vararg byte array.
14041404

1405-
SDValue VADeclareParam; // vararg byte array
1405+
SDValue VADeclareParam = SDValue(); // vararg byte array
14061406
const unsigned FirstVAArg = CLI.NumFixedArgs; // position of first variadic
14071407
unsigned VAOffset = 0; // current offset in the param array
14081408

@@ -1605,8 +1605,6 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
16051605
VAOffset += TypeSize;
16061606
}
16071607

1608-
GlobalAddressSDNode *Func = dyn_cast<GlobalAddressSDNode>(Callee.getNode());
1609-
16101608
// Handle Result
16111609
if (!Ins.empty()) {
16121610
const SDValue RetSymbol = DAG.getExternalSymbol("retval0", MVT::i32);
@@ -1619,10 +1617,9 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
16191617
}
16201618
}
16211619

1622-
const bool HasVAArgs = CLI.IsVarArg && (CLI.Args.size() > CLI.NumFixedArgs);
16231620
// Set the size of the vararg param byte array if the callee is a variadic
16241621
// function and the variadic part is not empty.
1625-
if (HasVAArgs) {
1622+
if (VADeclareParam) {
16261623
SDValue DeclareParamOps[] = {VADeclareParam.getOperand(0),
16271624
VADeclareParam.getOperand(1),
16281625
VADeclareParam.getOperand(2), GetI32(VAOffset),
@@ -1631,6 +1628,7 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
16311628
VADeclareParam->getVTList(), DeclareParamOps);
16321629
}
16331630

1631+
const auto *Func = dyn_cast<GlobalAddressSDNode>(Callee.getNode());
16341632
// If the type of the callsite does not match that of the function, convert
16351633
// the callsite to an indirect call.
16361634
const bool ConvertToIndirectCall = shouldConvertToIndirectCall(CB, Func);
@@ -1660,6 +1658,7 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
16601658
// instruction.
16611659
// The prototype is embedded in a string and put as the operand for a
16621660
// CallPrototype SDNode which will print out to the value of the string.
1661+
const bool HasVAArgs = CLI.IsVarArg && (CLI.Args.size() > CLI.NumFixedArgs);
16631662
std::string Proto =
16641663
getPrototype(DL, RetTy, Args, CLI.Outs,
16651664
HasVAArgs ? std::optional(FirstVAArg) : std::nullopt, *CB,
@@ -5729,6 +5728,15 @@ static SDValue combinePRMT(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
57295728
}
57305729

57315730

5731+
// During call lowering we wrap the return values in a ProxyReg node which
5732+
// depend on the chain value produced by the completed call. This ensures that
5733+
// the full call is emitted in cases where libcalls are used to legalize
5734+
// operations. To improve the functioning of other DAG combines we pull all
5735+
// operations we can through one of these nodes, ensuring that the ProxyReg
5736+
// directly wraps a load. That is:
5737+
//
5738+
// (ProxyReg (zext (load retval0))) => (zext (ProxyReg (load retval0)))
5739+
//
57325740
static SDValue sinkProxyReg(SDValue R, SDValue Chain,
57335741
TargetLowering::DAGCombinerInfo &DCI) {
57345742
switch (R.getOpcode()) {
@@ -5782,6 +5790,8 @@ static SDValue combineProxyReg(SDNode *N,
57825790
SDValue Chain = N->getOperand(0);
57835791
SDValue Reg = N->getOperand(1);
57845792

5793+
// If the ProxyReg is not wrapping a load, try to pull the operations through
5794+
// the ProxyReg.
57855795
if (Reg.getOpcode() != ISD::LOAD) {
57865796
if (SDValue V = sinkProxyReg(Reg, Chain, DCI))
57875797
return V;

0 commit comments

Comments
 (0)