This Idom check seems unnecessary. The immediate children of a node on the Dominator Tree should always be the IDom of its immediate children in this case.
Details
Diff Detail
- Build Status
Buildable 4872 Build 4872: arc lint + arc unit
Event Timeline
Sink.cpp | ||
---|---|---|
172 ↗ | (On Diff #78822) | Add a comment here to explain why you don't need to check. |
lib/Transforms/Scalar/Sink.cpp | ||
---|---|---|
174 | I wouldn't even bother with this assert. Honestly, this whole code is silly. If you want to take a whack at it, the proper (IMHO) way to do this is: ncdblock = find nearestcommondominator(blocks that contain uses) If ncdblock == Inst->getParent(), stop, can't sink. This will sink as low as possible. |
lib/Transforms/Scalar/Sink.cpp | ||
---|---|---|
174 | Thats what I have in mind as well. However, this would work well for sinking SSA values, but not memory reading/writing instructions. Sink.cpp has some simple abilities to sink loads and stores. |
lib/Transforms/Scalar/Sink.cpp | ||
---|---|---|
174 | By SSA values I meant instructions without reading/writing to memory. |
lib/Transforms/Scalar/Sink.cpp | ||
---|---|---|
174 | If we cared, we'd just run MemorySSA, and for loads/stores, and then you have the SSA form you need to sink stores |
Ok, I have not had the time to look at the MemorySSA work (I have plan to get to it in the near future). I will land this for now. This pass probably needs to be significantly changed (essentially rewritten) later if we need it.
I wouldn't even bother with this assert.
Just remove it and commit.
Honestly, this whole code is silly.
If you want to take a whack at it, the proper (IMHO) way to do this is:
ncdblock = find nearestcommondominator(blocks that contain uses)
If ncdblock == Inst->getParent(), stop, can't sink.
Otherwise,
while (!AcceptableTarget(Inst, ncdblock) && ncdblock != Inst->getParent())
, NCDBlock = getIDom(NCDBlock);
This will sink as low as possible.
You can then remove the allusesdominatedbyblock check from IsAcceptableTarget. Any idom of the ncd must, by definition, still dominate the uses.
Note that when computing NearestCommonDominator(uses), phi uses have to be considered to live at the end of the incoming block they come from to get optimal results.