[llvm] [AMDGPU] Eliminate likely-spurious execz checks via intrinsic argument (PR #123749)

Fabian Ritter via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 02:45:31 PST 2025


================
@@ -385,6 +418,62 @@ bool SIAnnotateControlFlow::run() {
   return Changed;
 }
 
+bool LikelyVaryingHeuristic::isRelevantSourceOfDivergence(
+    const Value *V) const {
+  auto *II = dyn_cast<IntrinsicInst>(V);
+  if (!II)
+    return false;
+
+  switch (II->getIntrinsicID()) {
+  case Intrinsic::amdgcn_workitem_id_z:
+  case Intrinsic::r600_read_tidig_z:
+  case Intrinsic::amdgcn_workitem_id_y:
+  case Intrinsic::r600_read_tidig_y:
+  case Intrinsic::amdgcn_workitem_id_x:
+  case Intrinsic::r600_read_tidig_x:
+  case Intrinsic::amdgcn_mbcnt_hi:
+  case Intrinsic::amdgcn_mbcnt_lo:
+    return true;
+  default:
+    return false;
+  }
+}
+
+bool LikelyVaryingHeuristic::isLikelyVarying(const Value *V) {
+  if (IsSingleLaneExecution)
+    return false;
+
+  if (isRelevantSourceOfDivergence(V))
+    return true;
+
+  auto *I = dyn_cast<Instruction>(V);
+  if (!I)
+    return false;
+
+  // ExtractValueInst and IntrinsicInst enable looking through the
+  // amdgcn_if/else intrinsics inserted by SIAnnotateControlFlow.
+  // This condition excludes PHINodes, which prevents infinite recursion.
----------------
ritter-x2a wrote:

With 5915dd42ecdee2fd4d471168fe1703472146d598, the heuristic also traverses phis and selects.

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


More information about the llvm-commits mailing list