@@ -1370,7 +1370,7 @@ void SelectionDAG::init(MachineFunction &NewMF,
13701370 const TargetLibraryInfo *LibraryInfo,
13711371 UniformityInfo *NewUA, ProfileSummaryInfo *PSIin,
13721372 BlockFrequencyInfo *BFIin, MachineModuleInfo &MMIin,
1373- FunctionVarLocs const *VarLocs) {
1373+ FunctionVarLocs const *VarLocs, bool HasDivergency ) {
13741374 MF = &NewMF;
13751375 SDAGISelPass = PassPtr;
13761376 ORE = &NewORE;
@@ -1383,6 +1383,7 @@ void SelectionDAG::init(MachineFunction &NewMF,
13831383 BFI = BFIin;
13841384 MMI = &MMIin;
13851385 FnVarLocs = VarLocs;
1386+ DivergentTarget = HasDivergency;
13861387}
13871388
13881389SelectionDAG::~SelectionDAG() {
@@ -2329,7 +2330,8 @@ SDValue SelectionDAG::getRegister(Register Reg, EVT VT) {
23292330 return SDValue(E, 0);
23302331
23312332 auto *N = newSDNode<RegisterSDNode>(Reg, VTs);
2332- N->SDNodeBits.IsDivergent = TLI->isSDNodeSourceOfDivergence(N, FLI, UA);
2333+ N->SDNodeBits.IsDivergent =
2334+ DivergentTarget && TLI->isSDNodeSourceOfDivergence(N, FLI, UA);
23332335 CSEMap.InsertNode(N, IP);
23342336 InsertNode(N);
23352337 return SDValue(N, 0);
@@ -12142,6 +12144,8 @@ static bool gluePropagatesDivergence(const SDNode *Node) {
1214212144}
1214312145
1214412146bool SelectionDAG::calculateDivergence(SDNode *N) {
12147+ if (!DivergentTarget)
12148+ return false;
1214512149 if (TLI->isSDNodeAlwaysUniform(N)) {
1214612150 assert(!TLI->isSDNodeSourceOfDivergence(N, FLI, UA) &&
1214712151 "Conflicting divergence information!");
@@ -12161,6 +12165,8 @@ bool SelectionDAG::calculateDivergence(SDNode *N) {
1216112165}
1216212166
1216312167void SelectionDAG::updateDivergence(SDNode *N) {
12168+ if (!DivergentTarget)
12169+ return;
1216412170 SmallVector<SDNode *, 16> Worklist(1, N);
1216512171 do {
1216612172 N = Worklist.pop_back_val();
@@ -13720,16 +13726,20 @@ void SelectionDAG::createOperands(SDNode *Node, ArrayRef<SDValue> Vals) {
1372013726 Ops[I].setInitial(Vals[I]);
1372113727 EVT VT = Ops[I].getValueType();
1372213728
13729+ // Take care of the Node's operands iff target has divergence
1372313730 // Skip Chain. It does not carry divergence.
13724- if (VT != MVT::Other &&
13731+ if (DivergentTarget && VT != MVT::Other &&
1372513732 (VT != MVT::Glue || gluePropagatesDivergence(Ops[I].getNode())) &&
1372613733 Ops[I].getNode()->isDivergent()) {
13734+ // Node is going to be divergent if at least one of its operand is
13735+ // divergent, unless it belongs to the "AlwaysUniform" exemptions.
1372713736 IsDivergent = true;
1372813737 }
1372913738 }
1373013739 Node->NumOperands = Vals.size();
1373113740 Node->OperandList = Ops;
13732- if (!TLI->isSDNodeAlwaysUniform(Node)) {
13741+ // Check the divergence of the Node itself.
13742+ if (DivergentTarget && !TLI->isSDNodeAlwaysUniform(Node)) {
1373313743 IsDivergent |= TLI->isSDNodeSourceOfDivergence(Node, FLI, UA);
1373413744 Node->SDNodeBits.IsDivergent = IsDivergent;
1373513745 }
0 commit comments