summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-11-30 09:34:29 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-11-30 09:34:29 +0000
commitd9ef81e1337a25130feb3658458fa5b27bbc8af6 (patch)
treef450171448cee90e6016f93c4e32164e004683d8 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent77d433dafe9ffa34293f3c1d188fefc769d5ed4f (diff)
downloadbcm5719-llvm-d9ef81e1337a25130feb3658458fa5b27bbc8af6.tar.gz
bcm5719-llvm-d9ef81e1337a25130feb3658458fa5b27bbc8af6.zip
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. llvm-svn: 168989
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 5a1b21025cc..f6d43a9e6ce 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3521,12 +3521,20 @@ static bool ShouldBuildLookupTable(SwitchInst *SI,
for (SmallDenseMap<PHINode*, Type*>::const_iterator I = ResultTypes.begin(),
E = ResultTypes.end(); I != E; ++I) {
Type *Ty = I->second;
- if (!TTI->getScalarTargetTransformInfo()->isTypeLegal(Ty))
- HasIllegalType = true;
- if (!SwitchLookupTable::WouldFitInRegister(TD, TableSize, Ty)) {
- AllTablesFitInRegister = false;
+
+ // Saturate this flag to true.
+ HasIllegalType = HasIllegalType ||
+ !TTI->getScalarTargetTransformInfo()->isTypeLegal(Ty);
+
+ // Saturate this flag to false.
+ AllTablesFitInRegister = AllTablesFitInRegister &&
+ SwitchLookupTable::WouldFitInRegister(TD, TableSize, Ty);
+
+ // If both flags saturate, we're done. NOTE: This *only* works with
+ // saturating flags, and all flags have to saturate first due to the
+ // non-deterministic behavior of iterating over a dense map.
+ if (HasIllegalType && !AllTablesFitInRegister)
break;
- }
}
// If each table would fit in a register, we should build it anyway.
OpenPOWER on IntegriCloud