[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
Wed Mar 29 05:52:29 PDT 2017


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

Add conditions to identify whether this phi is in a divergent region.


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,6 +86,7 @@
 class SIFixSGPRCopies : public MachineFunctionPass {
 
   MachineDominatorTree *MDT;
+  MachinePostDominatorTree *PDT;
 
 public:
   static char ID;
@@ -383,8 +385,20 @@
           MachineBasicBlock *MBB0 = MI.getOperand(2).getMBB();
           MachineBasicBlock *MBB1 = MI.getOperand(4).getMBB();
 
+          MachineDomTreeNode *IDN = NULL;
+          MachineBasicBlock *PNCD = NULL;
           MachineBasicBlock *NCD = MDT->findNearestCommonDominator(MBB0, MBB1);
-          if (NCD && !hasTerminatorThatModifiesExec(*NCD, *TRI)) {
+          if (MBB0->predecessors().begin() != MBB0->predecessors().end() &&
+              MBB1->predecessors().begin() != MBB1->predecessors().end()) {
+            NCD = PDT->findNearestCommonDominator(MBB0, MBB1);
+            if (PNCD) {
+              MachineDomTreeNode *N = MDT->getNode(PNCD);
+              IDN = N->getIDom();
+            }
+          }
+
+          if (NCD && !hasTerminatorThatModifiesExec(*NCD, *TRI) &&
+            IDN && !hasTerminatorThatModifiesExec(*PNCD, *TRI)) {
             DEBUG(dbgs() << "Not fixing PHI for uniform branch: " << MI << '\n');
             break;
           }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31350.93360.patch
Type: text/x-patch
Size: 1678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170329/9c7062b1/attachment.bin>


More information about the llvm-commits mailing list