Sort OpsToRename before iterating to make iteration order deterministic.
Thanks to Daniel Berlin for the sorting logic.
Differential D33265
[PredicateInfo] Fix non-determinism in codegen uncovered by reverse iterating SmallPtrSet mgrang on May 16 2017, 5:31 PM. Authored by
Details Sort OpsToRename before iterating to make iteration order deterministic. Thanks to Daniel Berlin for the sorting logic.
Diff Detail
Event TimelineComment Actions @davide The following two unit tests fail if run with -reverse-iterate : test/Transforms/Util/PredicateInfo/condprop.ll The cause of the failure is the difference in codegen due to iteration of OpsToRename: void PredicateInfo::renameUses(SmallSetVector<Value *, 8> &OpsToRename) { ValueDFS_Compare Compare(OBBMap); // Compute liveness, and rename in O(uses) per Op. for (auto *Op : OpsToRename) { Comment Actions Actually, please don't land this. If you want to make a SmallPtrSetVector, i'd be more willing to do this, otherwise, i'll just convert the relevant parts. (FWIW, i think running around the compiler and converting things from SmallPtrSet to to setvector is generally going to be a bad plan, and i'd be pretty opposed. We use SmallPtrSet because it's small and fast. SetVector is neither of these things. SmallSetVector is not *that much* better. ) Comment Actions uh, I'm very confused at this point, I thought this was resulting in non-deterministic output? Comment Actions As we did in NewGVN I think it's important to add a comment explaining why this doesn't matter, so, @mgrang, you might want to do that instead. Comment Actions (and in this case, the only place that needs any ordering is in renameUses, where we can just sort the input set of ops into a deterministic order, which we do for the uses anyway) Comment Actions https://reviews.llvm.org/differential/diff/99233/?revisionID=33265 Comment Actions Thanks @davide and @dberlin for your comments. Just wanted to confirm I understand this: In order to reuse the comparison function from ValueDFS_Compare in our case, we would have to move the localComesBefore function (or parts of it) out of ValueDFS_Compare so that both OBBMap and OpsToRename can use it as a comparator? ValueDFS_Compare constructor accepts BBs, so unless we first convert OpsToRename into ValueDFS (by calling our version of convertUsesToDFSOrdered) we cannot directly use it for sorting OpsToRename. Also is it OK to add -reverse-iterate to the two unit tests as I have done in my patch (so that we catch any future non-determinism arising out of this piece of code)? Comment Actions Ping for reviews please. (I know it's not been a week since I posted this patch, but it would be great if we could get this patch reviewed for an upcoming internal toolchain release). Thanks!
Comment Actions Sorry, this was marked as accepted because davide accepted the last version. |