[PATCH] D31350: AMDGPU : Fix common dominator of two incoming blocks terminates with uniform branch issue.

Wei Ding via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 30 16:15:31 PDT 2017


wdng updated this revision to Diff 93563.
wdng added a comment.

Completely remove weak if condition for checking whether two blocks with a uniform branch, current implementation uses divergence analysis to detect whether two blocks with a uniform branch. If all conditions on all paths leading to a block are uniform, block is uniform.


Repository:
  rL LLVM

https://reviews.llvm.org/D31350

Files:
  lib/Target/AMDGPU/SIFixSGPRCopies.cpp


Index: lib/Target/AMDGPU/SIFixSGPRCopies.cpp
===================================================================
--- lib/Target/AMDGPU/SIFixSGPRCopies.cpp
+++ lib/Target/AMDGPU/SIFixSGPRCopies.cpp
@@ -69,6 +69,7 @@
 #include "AMDGPUSubtarget.h"
 #include "SIInstrInfo.h"
 #include "llvm/CodeGen/MachineDominators.h"
+#include "llvm/CodeGen/MachinePostDominators.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
@@ -85,19 +86,21 @@
 class SIFixSGPRCopies : public MachineFunctionPass {
 
   MachineDominatorTree *MDT;
+  MachinePostDominatorTree *PDT;
 
 public:
   static char ID;
 
   SIFixSGPRCopies() : MachineFunctionPass(ID) { }
-
   bool runOnMachineFunction(MachineFunction &MF) override;
 
   StringRef getPassName() const override { return "SI Fix SGPR copies"; }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<MachineDominatorTree>();
     AU.addPreserved<MachineDominatorTree>();
+    AU.addRequired<MachinePostDominatorTree>();
+    AU.addPreserved<MachinePostDominatorTree>();
     AU.setPreservesCFG();
     MachineFunctionPass::getAnalysisUsage(AU);
   }
@@ -333,6 +336,7 @@
   const SIRegisterInfo *TRI = ST.getRegisterInfo();
   const SIInstrInfo *TII = ST.getInstrInfo();
   MDT = &getAnalysis<MachineDominatorTree>();
+  PDT = &getAnalysis<MachinePostDominatorTree>();
 
   SmallVector<MachineInstr *, 16> Worklist;
 
@@ -380,13 +384,19 @@
         // We don't need to fix the PHI if the common dominator of the
         // two incoming blocks terminates with a uniform branch.
         if (MI.getNumExplicitOperands() == 5) {
-          MachineBasicBlock *MBB0 = MI.getOperand(2).getMBB();
-          MachineBasicBlock *MBB1 = MI.getOperand(4).getMBB();
-
-          MachineBasicBlock *NCD = MDT->findNearestCommonDominator(MBB0, MBB1);
-          if (NCD && !hasTerminatorThatModifiesExec(*NCD, *TRI)) {
-            DEBUG(dbgs() << "Not fixing PHI for uniform branch: " << MI << '\n');
+          MachineDomTreeNode *N = PDT->getNode(MI.getParent());
+          if (!N)
             break;
+
+          MachineBasicBlock *IPostDom = N->getIDom() == NULL ? nullptr :
+                                                        N->getIDom()->getBlock();
+          if (IPostDom != NULL) {
+            for (auto I = IPostDom->getBasicBlock()->begin(); isa<PHINode>(I); ++I) {
+              if (!cast<PHINode>(I)->hasConstantValue()) {
+                DEBUG(dbgs() << "Not fixing PHI for uniform branch: " << MI << '\n');
+                break;
+              }
+            }
           }
         }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31350.93563.patch
Type: text/x-patch
Size: 2653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170330/c54dcf08/attachment.bin>


More information about the llvm-commits mailing list