@@ -308,6 +308,9 @@ class StructurizeCFG {
308308
309309  void  hoistZeroCostElseBlockPhiValues (BasicBlock *ElseBB, BasicBlock *ThenBB);
310310
311+   bool  isHoistableInstruction (Instruction *I, BasicBlock *BB,
312+                               BasicBlock *HoistTo);
313+ 
311314  void  orderNodes ();
312315
313316  void  analyzeLoops (RegionNode *N);
@@ -415,11 +418,21 @@ class StructurizeCFGLegacyPass : public RegionPass {
415418
416419} //  end anonymous namespace
417420
421+ char  StructurizeCFGLegacyPass::ID = 0 ;
422+ 
423+ INITIALIZE_PASS_BEGIN (StructurizeCFGLegacyPass, " structurizecfg"  ,
424+                       " Structurize the CFG"  , false , false )
425+ INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
426+ INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
427+ INITIALIZE_PASS_DEPENDENCY(RegionInfoPass)
428+ INITIALIZE_PASS_END(StructurizeCFGLegacyPass, " structurizecfg"  ,
429+                     " Structurize the CFG"  , false , false )
430+ 
418431// / Checks whether an instruction is zero cost instruction and checks if the
419432// / operands are from different BB. If so, this instruction can be coalesced
420433// / if its hoisted to predecessor block. So, this returns true.
421- static   bool  isHoistableInstruction (Instruction *I, BasicBlock *BB,
422-                                    const  TargetTransformInfo *TTI ) {
434+ bool StructurizeCFG:: isHoistableInstruction(Instruction *I, BasicBlock *BB,
435+                                             BasicBlock *HoistTo ) {
423436  if  (I->getParent () != BB || isa<PHINode>(I))
424437    return  false ;
425438
@@ -435,24 +448,14 @@ static bool isHoistableInstruction(Instruction *I, BasicBlock *BB,
435448  //  Check if any operands are instructions defined in the same block.
436449  for  (auto  &Op : I->operands ()) {
437450    if  (auto  *OpI = dyn_cast<Instruction>(Op)) {
438-       if  (OpI->getParent () == BB)
451+       if  (OpI->getParent () == BB || !DT-> dominates (OpI-> getParent (), HoistTo) )
439452        return  false ;
440453    }
441454  }
442455
443456  return  true ;
444457}
445458
446- char  StructurizeCFGLegacyPass::ID = 0 ;
447- 
448- INITIALIZE_PASS_BEGIN (StructurizeCFGLegacyPass, " structurizecfg"  ,
449-                       " Structurize the CFG"  , false , false )
450- INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
451- INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
452- INITIALIZE_PASS_DEPENDENCY(RegionInfoPass)
453- INITIALIZE_PASS_END(StructurizeCFGLegacyPass, " structurizecfg"  ,
454-                     " Structurize the CFG"  , false , false )
455- 
456459// / Structurization can introduce unnecessary VGPR copies due to register
457460// / coalescing interference. For example, if the Else block has a zero-cost
458461// / instruction and the Then block modifies the VGPR value, only one value is
@@ -478,7 +481,7 @@ void StructurizeCFG::hoistZeroCostElseBlockPhiValues(BasicBlock *ElseBB,
478481  for  (PHINode &Phi : ElseSucc->phis ()) {
479482    Value *ElseVal = Phi.getIncomingValueForBlock (ElseBB);
480483    auto  *Inst = dyn_cast<Instruction>(ElseVal);
481-     if  (!Inst || !isHoistableInstruction (Inst, ElseBB, TTI ))
484+     if  (!Inst || !isHoistableInstruction (Inst, ElseBB, CommonDominator ))
482485      continue ;
483486    Inst->removeFromParent ();
484487    Inst->insertInto (CommonDominator, Term->getIterator ());
0 commit comments