From 25bd884c3d0e9803dfafda10e7ecede152ad156f Mon Sep 17 00:00:00 2001 From: Christian Konig <christian.koenig@amd.com> Date: Sat, 16 Feb 2013 11:27:40 +0000 Subject: [PATCH] R600/structurizer: improve finding condition values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the new NearestCommonDominator class. This is a candidate for the stable branch. Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Tom Stellard <thomas.stellard@amd.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175347 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/R600/AMDGPUStructurizeCFG.cpp | 37 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/Target/R600/AMDGPUStructurizeCFG.cpp b/lib/Target/R600/AMDGPUStructurizeCFG.cpp index 38013476188..e97e049be58 100644 --- a/lib/Target/R600/AMDGPUStructurizeCFG.cpp +++ b/lib/Target/R600/AMDGPUStructurizeCFG.cpp @@ -458,28 +458,41 @@ void AMDGPUStructurizeCFG::insertConditions() { assert(Term->isConditional()); - PhiInserter.Initialize(Boolean, ""); - if (Parent == LoopEnd) { - PhiInserter.AddAvailableValue(LoopStart, BoolTrue); - } else { - PhiInserter.AddAvailableValue(&Func->getEntryBlock(), BoolFalse); - PhiInserter.AddAvailableValue(Parent, BoolFalse); - } + Value *Default = (Parent == LoopEnd) ? BoolTrue : BoolFalse; + + PhiInserter.Initialize(Boolean, ""); + PhiInserter.AddAvailableValue(&Func->getEntryBlock(), Default); + if (Parent == LoopEnd) + PhiInserter.AddAvailableValue(LoopStart, BoolTrue); + 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)); + } } }