[llvm] [AMDGPU] Eliminate likely-spurious execz checks via intrinsic argument (PR #123749)
Fabian Ritter via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 07:51:24 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:
I wouldn't say that this proposal is unable to handle phis; they are excluded here because I think that phi values are too complex for this simple heuristic optimization, since they depend on branch conditions.
The more complex the computation between the thread id and the branch condition, the less clear is the likelihood that the condition is dynamically varying.
I think we should only traverse through phis here if including phis whose values are affected by the thread id improves the heuristic.
https://github.com/llvm/llvm-project/pull/123749
More information about the llvm-commits
mailing list