llvm.org GIT mirror llvm / 66ea2f9
Fix non-determinism introduced in r168970 and pointed out by Duncan. We're iterating over a non-deterministically ordered container looking for two saturating flags. To do this correctly, we have to saturate both, and only stop looping if both saturate to their final value. Otherwise, which flag we see first changes the result. This is also a micro-optimization of the previous version as now we don't go into the (possibly expensive) test logic once the first violation of either constraint is detected. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168989 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
1 changed file(s) with 13 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
35203520 for (SmallDenseMap::const_iterator I = ResultTypes.begin(),
35213521 E = ResultTypes.end(); I != E; ++I) {
35223522 Type *Ty = I->second;
3523 if (!TTI->getScalarTargetTransformInfo()->isTypeLegal(Ty))
3524 HasIllegalType = true;
3525 if (!SwitchLookupTable::WouldFitInRegister(TD, TableSize, Ty)) {
3526 AllTablesFitInRegister = false;
3523
3524 // Saturate this flag to true.
3525 HasIllegalType = HasIllegalType ||
3526 !TTI->getScalarTargetTransformInfo()->isTypeLegal(Ty);
3527
3528 // Saturate this flag to false.
3529 AllTablesFitInRegister = AllTablesFitInRegister &&
3530 SwitchLookupTable::WouldFitInRegister(TD, TableSize, Ty);
3531
3532 // If both flags saturate, we're done. NOTE: This *only* works with
3533 // saturating flags, and all flags have to saturate first due to the
3534 // non-deterministic behavior of iterating over a dense map.
3535 if (HasIllegalType && !AllTablesFitInRegister)
35273536 break;
3528 }
35293537 }
35303538
35313539 // If each table would fit in a register, we should build it anyway.