[llvm] [AMDGPU] Eliminate likely-spurious execz checks via intrinsic argument (PR #123749)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 06:47:53 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.
----------------
arsenm wrote:
Usual way to handle this is to track a visited set while walking up the uses. You should be able to handle phis, including the recursive case
https://github.com/llvm/llvm-project/pull/123749
More information about the llvm-commits
mailing list