Is SDNode CopyFromReg necessary to be generated?

In the case SDNode CopyFromReg takes a virtual register and produces its value with type, is this node necessary to be generated for SelectionDAG? I tested some cases that ignores generating CopyFromReg and references the register Node directly also generates good code.


Hi Thomson

You’ll run into trouble here if the register class of the vreg isn’t compatible with that of the instruction generated which reads it. For example, you might have a vreg in an FP register bring read by an integer add. This would require that the CopyFromReg actually generate a cross class register copy to ensure this is valid code.

In SD you don’t know which actual instruction is going to be generated until late so you won’t have the information available to safely remove the copy. It’s probably best to just leave it there to avoid any potential issues.