[llvm] [AMDGPU] Hoist permlane64/readlane/readfirstlane through unary/binary operands (PR #129037)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 02:50:35 PDT 2025
================
@@ -481,6 +482,81 @@ bool GCNTTIImpl::simplifyDemandedLaneMaskArg(InstCombiner &IC,
return false;
}
+Instruction *
+GCNTTIImpl::hoistLaneIntrinsicThroughOperand(InstCombiner &IC,
+ IntrinsicInst &II) const {
+ const auto IID = II.getIntrinsicID();
+ assert(IID == Intrinsic::amdgcn_readlane ||
+ IID == Intrinsic::amdgcn_readfirstlane ||
+ IID == Intrinsic::amdgcn_permlane64);
+
+ Instruction *Op = dyn_cast<Instruction>(II.getOperand(0));
+
+ // Only do this if both instructions are in the same block
+ // (so the exec mask won't change) and the readlane is the only user of its
+ // operand.
+ if (!Op || !Op->hasOneUser() || Op->getParent() != II.getParent())
+ return nullptr;
+
+ const bool IsReadLane = (IID == Intrinsic::amdgcn_readlane);
+
+ // If this is a readlane, check that the second operand is a constant, or is
+ // defined before Op so we know it's safe to move this intrinsic higher.
+ Value *LaneID = nullptr;
+ if (IsReadLane) {
+ LaneID = II.getOperand(1);
+ // Check LaneID is available at Op, otherwise we can't move the readlane
+ // higher.
+ if (!IC.getDominatorTree().dominates(LaneID, Op))
+ return nullptr;
----------------
arsenm wrote:
Use isSafeToMoveBefore? I'm somewhat surprised you can do a dominates check on a constant
https://github.com/llvm/llvm-project/pull/129037
More information about the llvm-commits
mailing list