[llvm] [AMDGPU] Hoist permlane64/readlane/readfirstlane through unary/binary operands (PR #129037)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu May 1 02:32:30 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;
+ }
+
+ const auto DoIt = [&](unsigned OpIdx,
+ Function *NewIntrinsic) -> Instruction * {
----------------
arsenm wrote:
Yes, also the clone is also suspicious. I'd expect a Create or a clone, not both
https://github.com/llvm/llvm-project/pull/129037
More information about the llvm-commits
mailing list