Commit 53dae72a by Jim Stichnoth

Subzero: Deterministically sort local var stack offsets.

Currently, TargetLowering::sortVarsByAlignment() uses the variable's required alignment as the primary key, but then std::sort() breaks ties arbitrarily. This can give different results across different STL implementations, for example when building against LLVM trunk versus building in the PNaCl environment. The fix is to use Variable::Number as the secondary key. BUG= none R=kschimpf@google.com Review URL: https://codereview.chromium.org/2295393002 .
parent 7c9728fa
......@@ -737,8 +737,11 @@ void TargetLowering::sortVarsByAlignment(VarList &Dest,
// the buckets, if performance is an issue.
std::sort(Dest.begin(), Dest.end(),
[this](const Variable *V1, const Variable *V2) {
return typeWidthInBytesOnStack(V1->getType()) >
typeWidthInBytesOnStack(V2->getType());
const size_t WidthV1 = typeWidthInBytesOnStack(V1->getType());
const size_t WidthV2 = typeWidthInBytesOnStack(V2->getType());
if (WidthV1 == WidthV2)
return V1->getIndex() < V2->getIndex();
return WidthV1 > WidthV2;
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment