[llvm-commits] [llvm] r168989 - /llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Chandler Carruth chandlerc at gmail.com
Fri Nov 30 01:34:29 PST 2012


Author: chandlerc
Date: Fri Nov 30 03:34:29 2012
New Revision: 168989

URL: http://llvm.org/viewvc/llvm-project?rev=168989&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=168989&r1=168988&r2=168989&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Fri Nov 30 03:34:29 2012
@@ -3521,12 +3521,20 @@
   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.





More information about the llvm-commits mailing list