[llvm] [HLSL][DirectX] Avoid visited values when searching in `hasNonUniformIndex` (PR #189498)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 16:10:48 PDT 2026


=?utf-8?q?João?= Saffran <joaosaffranllvm at gmail.com>,Joao Saffran
 <jderezende at microsoft.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/189498 at github.com>


================
@@ -251,23 +251,35 @@ class OpLowerer {
     if (isa<llvm::Constant>(IndexOp))
       return false;
 
-    SmallVector<Value *> WorkList;
-    WorkList.push_back(IndexOp);
-
-    while (!WorkList.empty()) {
-      Value *V = WorkList.pop_back_val();
-      if (auto *CI = dyn_cast<CallInst>(V)) {
-        if (CI->getCalledFunction()->getIntrinsicID() ==
-            Intrinsic::dx_resource_nonuniformindex)
+    SmallVector<Value *, 16> Worklist;
+    SmallPtrSet<Value *, 16> Visited;
+    Worklist.push_back(IndexOp);
+
+    while (!Worklist.empty()) {
+      Value *V = Worklist.pop_back_val();
+
+      if (isa<llvm::Constant>(V))
+        continue;
+
+      if (!Visited.insert(V).second)
+        continue;
+
+      if (auto *CI = dyn_cast<CallInst>(V))
+        if (CI->getIntrinsicID() == Intrinsic::dx_resource_nonuniformindex)
           return true;
+
+      // If it's a PHI node, check ALL incoming values —
+      // taint from ANY predecessor counts
+      if (auto *Phi = dyn_cast<PHINode>(V)) {
+        for (Value *Incoming : Phi->incoming_values())
+          Worklist.push_back(Incoming);
+        continue;
       }
-      if (auto *U = llvm::dyn_cast<llvm::User>(V)) {
-        for (llvm::Value *Op : U->operands()) {
-          if (isa<llvm::Constant>(Op))
-            continue;
-          WorkList.push_back(Op);
-        }
-      }
+
+      if (auto *Inst = dyn_cast<Instruction>(V))
+        if (Inst->getNumOperands() > 0 && !Inst->isTerminator())
+          for (Value *Op : Inst->operands())
+            Worklist.push_back(Op);
----------------
joaosaffran wrote:

This is already handled right after we pop from the Worklist. Do you want me to add in there as well?

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


More information about the llvm-commits mailing list