This is an archive of the discontinued LLVM Phabricator instance.

[RewriteStatepointsForGC] Stabilise rematerialization order
AbandonedPublic

Authored by igor-laevsky on Apr 22 2016, 11:06 AM.

Details

Reviewers
sanjoy
Summary

This patch fixes non-determinism we had during rematerialization of the live values. There were two sources of it:

  1. We need to iterate through rematerialization candidates in a stable order. Fix is achieved by sorting them prior to the loop (similarly to other places in this pass)
  2. We used DenseSet to keep already rematerialized values. Fixed by changing storage from DenseSet to vector of pairs.

Diff Detail

Event Timeline

igor-laevsky retitled this revision from to [RewriteStatepointsForGC] Stabilise rematerialization order.
igor-laevsky updated this object.
igor-laevsky added a reviewer: sanjoy.
igor-laevsky added a subscriber: llvm-commits.
sanjoy requested changes to this revision.Apr 22 2016, 1:51 PM
sanjoy edited edge metadata.

Hi Igor,

I had something different in mind: I'd have preferred a systematic
"deterministic by construction" approach, not "at a certain point,
stabilize the order to something quasi-deterministic". For instance,
I think you're still relying on pointer comparison in order_by_name
for unnamed values.

I'd prefer that we figure out why there is any non-determinism in the
first place (e.g. one suspicious bit is that StatepointLiveSetTy is
a DenseSet, perhaps it should be a SetVector?), fix those sources
of non-determinism and ultimately get rid of these stabilization steps
altogether.

Does that sound reasonable?

This revision now requires changes to proceed.Apr 22 2016, 1:51 PM

Hi Sanjoy,

It would be preferable to have determinism by construction. However in order to
get it we will need to not only change StatepointLiveSetTy type, but also
change all data types associated with liveness/basepointer analysis.

I'm afraid by doing so we will spend considerable amount of resources
(SetVector's and MapVector's are more expensive). And since this issue is not
directly related to correctness I would go with this non-perfect approach.

So what do you think? Basically we will consume twice as much memory for sustaining order via SetVector/MapVector. And since we only need stable order in certain points and not during whole pass run, I think it's fine to keep explicit sorting. We should probably hoist such code into a clear helper function though.

So what do you think? Basically we will consume twice as much memory for sustaining order via SetVector/MapVector. And since we only need stable order in certain points and not during whole pass run, I think it's fine to keep explicit sorting. We should probably hoist such code into a clear helper function though.

I'd say if the additional time or space consumption creates trouble, we can consider moving to a cleverer algorithm (i.e. doing less work because doing the same units of work is more expensive). For now, given that non-determinism in this pass leads to actual codegen differences, I'm fairly inclined to make things deterministic by construction.

igor-laevsky abandoned this revision.Apr 28 2016, 10:06 AM

Ok, makes sense. Please take a look at the http://reviews.llvm.org/D19669