This is an archive of the discontinued LLVM Phabricator instance.

[MachinePipeliner] Avoid indeterminate order in FuncUnitSorter
ClosedPublic

Authored by jsji on Aug 8 2019, 7:51 PM.

Details

Summary

This is exposed by adding a new testcase in PowerPC in
https://reviews.llvm.org/rL367732

The testcase got different output on different platform, hence breaking
buildbots.

The problem is that we get differnt FuncUnitOrder when calculateResMII.

The root cause is:

  1. Two MachineInstr might get SAME priority(MFUsx) from minFuncUnits.
  2. Current comparison operator() will return MFUs1 > MFUs2.
  3. We use iterators for MachineInstr, so the input to FuncUnitSorter might be different on differnt platform due to the iterator nature.

So for two MI with same MFU, their order is actually depends on the
iterator order, which is platform (implemtation) dependent.

This is risky, and may cause cross-compiling problems.

The fix is to check make sure we assign a determine order when they are
equal.

Diff Detail

Repository
rL LLVM

Event Timeline

jsji created this revision.Aug 8 2019, 7:51 PM
jmolloy accepted this revision.Aug 9 2019, 1:21 AM

LGTM. Note for other reviewers; the canonical way to avoid this in LLVM is to use a stable_sort. The reason we can't do this is because this functor is used as the comparison for a std::priority_queue (heap) rather than a plain sort.

This revision is now accepted and ready to land.Aug 9 2019, 1:21 AM
bcahoon accepted this revision.Aug 9 2019, 6:39 AM

Thanks for the patch! My only concern is with all the checks in the test case. Checking for the exact code sequence can be very sensitive to other changes in the compiler that are unrelated to this patch.

Thanks,
Brendon

jsji added a comment.Aug 9 2019, 6:53 AM

Thanks for the patch! My only concern is with all the checks in the test case. Checking for the exact code sequence can be very sensitive to other changes in the compiler that are unrelated to this patch.

Thanks,
Brendon

Thanks Brendon!
Yes, agree, the testcases was originally for James's refactoring, so far I added those CHECK intentionality to catch any potential impacts to machine pipeliner on PowerPC.
I will relax the checks in all similar testcases later once machine pipeliner on PowerPC become stable enough.

This revision was automatically updated to reflect the committed changes.