[llvm] r175347 - R600/structurizer: improve finding condition values

Christian Konig christian.koenig at amd.com
Sat Feb 16 03:27:40 PST 2013


Author: ckoenig
Date: Sat Feb 16 05:27:40 2013
New Revision: 175347

URL: http://llvm.org/viewvc/llvm-project?rev=175347&view=rev
Log:
R600/structurizer: improve finding condition values

Using the new NearestCommonDominator class.

This is a candidate for the stable branch.

Signed-off-by: Christian König <christian.koenig at amd.com>
Reviewed-by: Tom Stellard <thomas.stellard at amd.com>

Modified:
    llvm/trunk/lib/Target/R600/AMDGPUStructurizeCFG.cpp

Modified: llvm/trunk/lib/Target/R600/AMDGPUStructurizeCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/AMDGPUStructurizeCFG.cpp?rev=175347&r1=175346&r2=175347&view=diff
==============================================================================
--- llvm/trunk/lib/Target/R600/AMDGPUStructurizeCFG.cpp (original)
+++ llvm/trunk/lib/Target/R600/AMDGPUStructurizeCFG.cpp Sat Feb 16 05:27:40 2013
@@ -458,28 +458,41 @@ void AMDGPUStructurizeCFG::insertConditi
 
     assert(Term->isConditional());
 
+    Value *Default = (Parent == LoopEnd) ? BoolTrue : BoolFalse;
+
     PhiInserter.Initialize(Boolean, "");
-    if (Parent == LoopEnd) {
+    PhiInserter.AddAvailableValue(&Func->getEntryBlock(), Default);
+    if (Parent == LoopEnd)
       PhiInserter.AddAvailableValue(LoopStart, BoolTrue);
-    } else {
-      PhiInserter.AddAvailableValue(&Func->getEntryBlock(), BoolFalse);
+    else
       PhiInserter.AddAvailableValue(Parent, BoolFalse);
-    }
 
-    bool ParentHasValue = false;
     BasicBlock *Succ = Term->getSuccessor(0);
     BBPredicates &Preds = (Parent == LoopEnd) ? LoopPred : Predicates[Succ];
+
+    NearestCommonDominator Dominator(DT);
+    Dominator.addBlock(Parent, false);
+
+    Value *ParentValue = 0;
     for (BBPredicates::iterator PI = Preds.begin(), PE = Preds.end();
          PI != PE; ++PI) {
 
+      if (PI->first == Parent) {
+        ParentValue = PI->second;
+        break;
+      }
       PhiInserter.AddAvailableValue(PI->first, PI->second);
-      ParentHasValue |= PI->first == Parent;
+      Dominator.addBlock(PI->first);
     }
 
-    if (ParentHasValue)
-      Term->setCondition(PhiInserter.GetValueAtEndOfBlock(Parent));
-    else
+    if (ParentValue) {
+      Term->setCondition(ParentValue);
+    } else {
+      if (!Dominator.wasResultExplicitMentioned())
+        PhiInserter.AddAvailableValue(Dominator.getResult(), Default);
+
       Term->setCondition(PhiInserter.GetValueInMiddleOfBlock(Parent));
+    }
   }
 }
 





More information about the llvm-commits mailing list