This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Fix a debug invariant bug in FoldBranchToCommonDest()
ClosedPublic

Authored by dstenb on May 9 2018, 4:22 AM.

Details

Summary

Fix a case where FoldBranchToCommonDest() would bail out from doing CSE
when encountering a debug intrinsic. Handle that by skipping past the
debug intrinsics.

Also, as a minor refactoring, rename checkCSEInPredecessor() to
tryCSEWithPredecessor() to make it a bit more clear that the function
may remove instructions.

Diff Detail

Event Timeline

dstenb created this revision.May 9 2018, 4:22 AM
davide added a subscriber: davide.May 9 2018, 8:10 AM
davide added inline comments.
lib/Transforms/Utils/SimplifyCFG.cpp
2580–2585

Can Cond be a DbgInfoIntrinsic here?

vsk added a subscriber: vsk.May 9 2018, 4:29 PM
vsk added inline comments.
lib/Transforms/Utils/SimplifyCFG.cpp
2559

Can this simply be written as: for (auto &Curr : BB->instructionsWithoutDebug())?

dstenb added inline comments.May 10 2018, 3:32 AM
lib/Transforms/Utils/SimplifyCFG.cpp
2559

As we may erase instructions, I don't think we can use a range-based for loop here.

2580–2585

I guess that Cond is guaranteed to be a CmpInst or BinaryOperator here, based on the guard on line 2575.

fhahn added inline comments.May 10 2018, 3:39 AM
lib/Transforms/Utils/SimplifyCFG.cpp
2559

Yep, unfortunately this is quite a widespread pattern which prevents us from using range-based loops.... Maybe there's something nicer/ more generic we could do in such cases, but I think that would require some further investigation.

test/Transforms/SimplifyCFG/fold-branch-debuginvariant.ll
8

Could you use CHECK-LABEL here and for bb2?

9

nit: IMO it is slightly clearer when matching the operands too: and i1 false, false would

dstenb updated this revision to Diff 146115.May 10 2018, 4:57 AM

Addressed comments!

dstenb marked 2 inline comments as done.May 10 2018, 4:58 AM

Any more comments on this?

fhahn accepted this revision.May 17 2018, 2:50 AM

LGTM, thanks. Please wait a bit with committing in case @davide (or anybody else) has any more comments.

This revision is now accepted and ready to land.May 17 2018, 2:50 AM
xbolva00 accepted this revision.May 17 2018, 9:32 AM

Thanks for the reviews! I'll submit this shortly.

This revision was automatically updated to reflect the committed changes.