This is an archive of the discontinued LLVM Phabricator instance.

Use a stable-sort when combining bases
ClosedPublic

Authored by saugustine on Mar 16 2022, 4:40 PM.

Details

Summary

While experimenting with different algorithms for std::sort
I discovered that combine-vmovdrr.ll fails if this sort is not
stable.

I suspect that the test is too stringent in its check--the resultant
code looks functionally identical to me under both stable and unstable
sorting, but a generic fix is quite a bit more difficult to implement.

Thanks to scw@google.com for finding the proper fix.

Diff Detail

Event Timeline

saugustine created this revision.Mar 16 2022, 4:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 4:40 PM
saugustine requested review of this revision.Mar 16 2022, 4:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 4:40 PM
efriedma accepted this revision.Mar 16 2022, 9:13 PM
efriedma added a subscriber: efriedma.

LGTM

I suspect that the test is too stringent in its check--the resultant code looks functionally identical to me under both stable and unstable sorting,

We don't want the code generated by LLVM to depend on the way std::sort is implemented. Even if there isn't any functional difference, any sort of non-determinism makes it harder to understand bugs or performance issues. (Output changing based on the host C++ library isn't as bad as cases where it depends on ASLR randomization or something like that, but still.)

This revision is now accepted and ready to land.Mar 16 2022, 9:13 PM
MaskRay accepted this revision.Mar 16 2022, 11:06 PM

LGTM

I suspect that the test is too stringent in its check--the resultant code looks functionally identical to me under both stable and unstable sorting,

We don't want the code generated by LLVM to depend on the way std::sort is implemented. Even if there isn't any functional difference, any sort of non-determinism makes it harder to understand bugs or performance issues. (Output changing based on the host C++ library isn't as bad as cases where it depends on ASLR randomization or something like that, but still.)

Agree. libc++ now provides -D_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY (D96946, or via _LIBCPP_DEBUG=1) to randomize std::sort.
Some build bots using libc++ may consider switching to this mode.

This revision was landed with ongoing or failed builds.Mar 17 2022, 9:04 AM
This revision was automatically updated to reflect the committed changes.

This change breaks some CI. Precheck even failed on this. Can you revert,

craig.topper added inline comments.
llvm/lib/Target/ARM/ARMISelLowering.cpp
15981

lambda needs to use const references that's probably what's causing the breakage.