[llvm] [AMDGPU] Hoist readlane/readfirst through unary/binary operands (PR #129037)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 27 03:14:04 PST 2025
================
@@ -481,6 +481,59 @@ bool GCNTTIImpl::simplifyDemandedLaneMaskArg(InstCombiner &IC,
return false;
}
+Instruction *GCNTTIImpl::hoistReadLaneThroughOperand(InstCombiner &IC,
+ IntrinsicInst &II) const {
+ 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 = (II.getIntrinsicID() == 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);
+ if (!isa<Constant>(LaneID) && !(isa<Instruction>(LaneID) &&
+ cast<Instruction>(LaneID)->comesBefore(Op)))
----------------
arsenm wrote:
should use isTriviallyUniform helper
https://github.com/llvm/llvm-project/pull/129037
More information about the llvm-commits
mailing list