This is an archive of the discontinued LLVM Phabricator instance.

Update edge weights properly when merging blocks in if-conversion.
ClosedPublic

Authored by congh on Aug 31 2015, 6:15 PM.

Details

Summary

In if-conversion, there is a utility function MergeBlocks() that is used to merge blocks. However, when new edges are built in this function the edge weight is either not provided or not updated properly, leading to a modified CFG with incorrect edge weights. This patch corrects this issue. More information is provided in the comments.

Diff Detail

Repository
rL LLVM

Event Timeline

congh updated this revision to Diff 33655.Aug 31 2015, 6:15 PM
congh retitled this revision from to Update edge weights properly when merging blocks in if-conversion..
congh updated this object.
congh added reviewers: MatzeB, qcolombet, davidxl.
congh added a subscriber: llvm-commits.
davidxl edited edge metadata.Sep 1 2015, 1:52 PM

I'd like profile update to be isolated in its own helper function. Have some examples in the comments (like in the test case) -- the example should show cfg before and after. The parameters also need to be documented.

lib/CodeGen/IfConversion.cpp
1701 ↗(On Diff #33655)

Should it be zero?

1736 ↗(On Diff #33655)

Do you have example of this case?

congh added a comment.Sep 1 2015, 2:34 PM

I'd like profile update to be isolated in its own helper function. Have some examples in the comments (like in the test case) -- the example should show cfg before and after. The parameters also need to be documented.

It is difficult to isolate profile update here as the profile data is needed when adding successors.

I have added a CFG example to the comment in this function. Some variables are also documented.

lib/CodeGen/IfConversion.cpp
1701 ↗(On Diff #33655)

I made a mistake here: I should get To2FromWeight before the edge weight is set to zero. Need to switch this statement with the one above.

1736 ↗(On Diff #33655)

Yes. The test case in test/CodeGen/ARM/ifcvt-iter-indbr.ll covers this case.

congh updated this revision to Diff 33729.Sep 1 2015, 2:35 PM
congh edited edge metadata.

Fixed a bug in the patch and added more comments.

congh edited reviewers, added: pete; removed: davidxl.Sep 10 2015, 1:20 PM
congh added a reviewer: hans.Sep 17 2015, 4:51 PM
hans accepted this revision.Sep 18 2015, 11:23 AM
hans edited edge metadata.

Looks ok to me. The code is pretty hard to follow, but I don't have any great ideas for making it easier.

lib/CodeGen/IfConversion.cpp
1689 ↗(On Diff #33729)

I know this is old code, but while you're here, maybe change this to a SmallVector and rename to FromSuccs?

test/CodeGen/ARM/ifcvt-iter-indbr.ll
2 ↗(On Diff #33729)

Should 2<&1 be 2>&1?

This revision is now accepted and ready to land.Sep 18 2015, 11:23 AM
In D12513#248922, @hans wrote:

Looks ok to me. The code is pretty hard to follow, but I don't have any great ideas for making it easier.

Thanks for the review! Yes, this part is not easy to understand but I also could not find a way to improve the overall readability.

lib/CodeGen/IfConversion.cpp
1689 ↗(On Diff #33729)

Done. I found many uses of std::vector in this file. Do we need to change all of them to SmallVector?

test/CodeGen/ARM/ifcvt-iter-indbr.ll
2 ↗(On Diff #33729)

Right.. corrected.

hans added inline comments.Sep 18 2015, 12:00 PM
lib/CodeGen/IfConversion.cpp
1689 ↗(On Diff #33729)

You could look at them in a separate patch if you like, but it's probably not very important.

I figured this one would be nice to fix when you're editing the function already.

This revision was automatically updated to reflect the committed changes.