It seems orderings are not assigned to DAG nodes created after the DAG builder, e.g., DAG nodes created during legalization. This causes instructions being scheduled in different order than source order for O0.
This is my plan to fix it:
Make a utility routine that recursively assign ordering to a chain of nodes, just like what SelectionDAGBuilder::AssignOrderingToNode() does.
Then add call to this utility routine at each routine that creates new DAG nodes after DAG builder to transfer the original node’s order to newly created node. If that routine creates a chain of nodes, then I only need to call the utility routine for the last of the chain. There will be a lot of places to change. So I want to get agreement on the fix before I go ahead and make the changes.
Do you still see this behavior after r177525? I recently fixed several places where ordering was not propagated, including during legalization. There are probably still cases that are missed, but I’d be interested in seeing a missed case. I’m guessing it’s a legalization that expands to multiple new nodes. The AssignOrdering calls in the legalizer may need to be expanded to do the traversal you mention from SelectionDAGBuilder.
Our code is using llvm3.1. I didn’t check the top of chunk. And I wasn’t following the mailing list closely. So I wasn’t aware of your fix.
I talked to Andy today. To fix the problem one step further, I am going to make the change that he suggested in his earlier email to include the ordering as a field in the DAG node itself, and have the ordering setup when the node is constructed.