I encounter a problem with DAG.getMemIntrinsicNode;
when I use DAG.getNode, it would give me the SDNode if there already has identical one instead of create a new one;
but when I use DAG.getMemIntrinsicNode, it alway create a new SDNode no matter if there has a identical one in the DAG tree;
after debug the code, I find the reason is the ID key computation is not the same when insert to map and when query from the map;
SDValue SelectionDAG::getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl,
SDVTList VTList,
ArrayRef<SDValue> Ops, EVT MemVT,
MachineMemOperand *MMO) {
...
MemIntrinsicSDNode *N;
if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) {
FoldingSetNodeID ID;
AddNodeIDNode(ID, Opcode, VTList, Ops);
/*
Here is the problem, it added a subclassData into the ID,
But when the node insert to the map, it did not add the subclassData into the ID;
*/
ID.AddInteger(getSyntheticNodeSubclassData<MemIntrinsicSDNode>(
Opcode, dl.getIROrder(), VTList, MemVT, MMO));
ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
void *IP = nullptr;
if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP)) {
cast<MemIntrinsicSDNode>(E)->refineAlignment(MMO);
return SDValue(E, 0);
}
N = newSDNode<MemIntrinsicSDNode>(Opcode, dl.getIROrder(), dl.getDebugLoc(),
VTList, MemVT, MMO);
createOperands(N, Ops);
CSEMap.InsertNode(N, IP);
...
static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N) {
switch (N->getOpcode()) {
...
case ISD::LOAD: {
const LoadSDNode *LD = cast<LoadSDNode>(N);
ID.AddInteger(LD->getMemoryVT().getRawBits());
/*
For the LOAD, it would be add the SubclassData into the FoldingSetNodeID;
*/
ID.AddInteger(LD->getRawSubclassData());
ID.AddInteger(LD->getPointerInfo().getAddrSpace());
break;
...
} // end switch (N->getOpcode())
// Target specific memory nodes could also have address spaces to check.
if (N->isTargetMemoryOpcode()) {
const MemSDNode *MN = cast<MemSDNode>(N);
/*
Here is the ID creator when insert the Node into the CSEMap;
For the MemSDNode created by getMemIntrinsicNode, it did not add the SubclassData into the ID;
If I add the codes below, it would reuse the same MemSDNode
ID.AddInteger(MN->getRawSubclassData());
*/
ID.AddInteger(MN->getPointerInfo().getAddrSpace());
}
}