This is an archive of the discontinued LLVM Phabricator instance.

[LoopSink] Don't sort BBs if there is only 1 of them (NFC)
ClosedPublic

Authored by danlark on Aug 15 2023, 1:52 AM.

Details

Summary

This was trigerred by the debug check when comp(a, a) was called.
On line 216 it's checked that LoopBlockNumber should contain
all if there are more than 1. NFC for end users

I don't have commit rights. Danila Kutenin. kutdanila@yandex.ru

Diff Detail

Event Timeline

danlark created this revision.Aug 15 2023, 1:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 1:52 AM
danlark requested review of this revision.Aug 15 2023, 1:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 1:52 AM
nikic added a comment.Aug 15 2023, 1:55 AM

Which debug check did this trigger? Do you have a test case?

danlark added a comment.EditedAug 15 2023, 1:59 AM

Which debug check did this trigger? Do you have a test case?

If you build llvm with libcxx at head as a standard library with -D_LIBCPP_DEBUG_STRICT_WEAK_ORDERING_CHECK and -D_LIBCPP_ENABLE_DEBUG_MODE, then for this sorting it will invoke comp(a, a) for llvm/test/Transforms/LICM/loopsink.ll.test

This change is extremely safe, on line 216 it's checked that llvm::set_is_subset(BBsToSinkInto, LoopBlockNumber) if BBsToSinkInto.size() > 1. If it's size 1, it implicitly thought no comparator would be called. But it can and LoopBlockNumber.find(A)->second will be a .end() iterator dereference

nikic accepted this revision.Aug 15 2023, 2:54 AM

LGTM. Took me a while to get it, but you're saying that by default sort with one element will not invoke the comparison callback, while in debug mode it will be done to verify the strict weak ordering. That's why we did not previously hit the assertion failure.

I'm not sure whether this is really the right fix (possibly the earlier BBsToSinkInto.size() > 1 check should be removed), but this is fine to fix the assertion failure while keeping the current behavior.

This revision is now accepted and ready to land.Aug 15 2023, 2:54 AM

Please, submit on my behalf

This revision was landed with ongoing or failed builds.Aug 16 2023, 1:06 AM
This revision was automatically updated to reflect the committed changes.