Add DAGNode After Load

I need to add a custom DAGNode after a extloadf32. Currently trying to add node within customLowering LowerLoad(possibly not the right approach).

But I keep getting errors and not sure how to accomplish this . What I’m asking is there a correct way to do this or just not possible?

Using this to catch the extloadf32 to a lower operation to lower load:
setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Custom);

Lower Load :
SDValue XXXTargetLowering::LowerLOAD(SDValue Op,SelectionDAG &DAG) const {
SDLoc DL(Op);
LoadSDNode *LoadNode = cast(Op);
SDValue SFTD = DAG.getNode(XXXISD:SFTD, DL, MVT::f64, Op);
DAG.ReplaceAllUsesOfValueWith(Op, SFTD);
return Op;
}

The problem is I’m trying to replace all the uses of the result of the load using ReplaceAllUsesofValue() but then the DAG node for SFTD gets messed up: t17: f64 XXXISD:SFTD t17 as SFTD takes the input “Op”. What’s the correct way to fix the uses but the DAG would be correct.

What I want to accomplish:
t16 : f64,ch = load…
t17 : f64 = XXXISD:SFTD t16
t18 : ch = store… t16:1, t17

What happens:
t16 : f64,ch = load…
t17 : f64 = XXXISD:SFTD t17
t18 : ch = store… t16:1, t17

That is a problem indeed. Node replacement is handled by the lowering algorithm, you just need to return the legalized code.

Edit: Be aware that if you return identical load, just wrapped in the extra SFTD operation, the lowering code will call your function again on the load.

How do I return just the legalized code when the result type of the custom instruction is only one value when it needs two as it’s checking for the chain of the load.

Use SelectionDAG::getMergeValues.

1 Like