Invalid number for the given node in SelectionDAG

I’m trying to replace SDIvRem (whch returns two i16 types) with a custom that returns i32 or i16. I am getting the Assertion (!Node || ResNo < Node->getNumValues() && “Invalid result number for the given node!”)

Seems that it doesn’t like returning one value but how do you return more than one value?

I am doing this in the LowerOperation for the case SDIVREM and a function LowerSDIVREM inside XXXISelLowering.cpp

I looked at some other cases, such as arm, and it generates a pair and then returns the first of the pair, this does not work for me however.

Thanks.

Hi Ryan,

Seems that it doesn't like returning one value but how do you return more
than one value?

You create the node using a getNode call that takes either an
ArrayRef<EVT> or an SDVTList instead of a single EVT result type. Then
you almost always need to write C++ code in ISelDAGToDAG to select it
properly.

Alternatively, you could lower it to multiple instructions (e.g.
division, multiplication and subtraction) and then recombine them at
the end with a MERGE_VALUES node as above. Then since each actual
instruction only has one value, normal TableGen could handle selection
and the generic infrastructure will take care of the MERGE_VALUES.

I looked at some other cases, such as arm, and it generates a pair and then
returns the first of the pair, this does not work for me however.

The pair in the ARM case is unrelated to the pair in the DIVREM
itself. The second SDValue is the chain that any function call will
produce for ordering purposes, which isn't needed because no
load/store/side-effecty things can depend on a DIVREM.

That first SDValue will be a node with two results as I described above.

Cheers.

Tim.

Tim,

Thanks for the reply. I found the merge values function and am trying that route now.

Thanks.