[llvm] [AMDGPU] SelectionDAG divergence tracking should take into account Target divergency. (PR #144947)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 09:26:15 PDT 2025


================
@@ -13600,22 +13600,29 @@ void SelectionDAG::createOperands(SDNode *Node, ArrayRef<SDValue> Vals) {
   SDUse *Ops = OperandRecycler.allocate(
       ArrayRecycler<SDUse>::Capacity::get(Vals.size()), OperandAllocator);
 
+  // Init it to "false" even fro not divergent targets as there is no other init
+  // point for it
+  Node->SDNodeBits.IsDivergent = false;
   bool IsDivergent = false;
   for (unsigned I = 0; I != Vals.size(); ++I) {
     Ops[I].setUser(Node);
     Ops[I].setInitial(Vals[I]);
     EVT VT = Ops[I].getValueType();
 
+    // Take care of the Node's operands iif target has divergence
     // Skip Chain. It does not carry divergence.
-    if (VT != MVT::Other &&
+    if (DivergentTarget && VT != MVT::Other &&
         (VT != MVT::Glue || gluePropagatesDivergence(Ops[I].getNode())) &&
         Ops[I].getNode()->isDivergent()) {
+      // Node is going to be divergent if at least one of its operand is
+      // divergent, unless it belongs to the "AlwaysUniform" exemptions.
       IsDivergent = true;
     }
   }
   Node->NumOperands = Vals.size();
   Node->OperandList = Ops;
-  if (!TLI->isSDNodeAlwaysUniform(Node)) {
+  // Check the divergence of the Node itself.
+  if (DivergentTarget && !TLI->isSDNodeAlwaysUniform(Node)) {
     IsDivergent |= TLI->isSDNodeSourceOfDivergence(Node, FLI, UA);
     Node->SDNodeBits.IsDivergent = IsDivergent;
----------------
jayfoad wrote:

Hmm, OK. But you don't need the init on line 13605 anyway, because the SDNode constructor memsets all the node bits to zero.

https://github.com/llvm/llvm-project/pull/144947


More information about the llvm-commits mailing list