[llvm] [AMDGPU][InstCombine] Fold unused m0 operand to poison for sendmsg intrinsics (PR #183755)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 00:21:31 PST 2026
================
@@ -1448,6 +1448,33 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
// amdgcn.kill(i1 1) is a no-op
return IC.eraseInstFromFunction(II);
}
+ case Intrinsic::amdgcn_s_sendmsg:
+ case Intrinsic::amdgcn_s_sendmsghalt: {
+ // The second operand is copied to m0, but is only actually used for
+ // certain message types. For message types that are known to not use m0,
+ // fold it to poison.
+ using namespace AMDGPU::SendMsg;
+
+ Value *M0Val = II.getArgOperand(1);
+ if (isa<PoisonValue>(M0Val))
+ break;
+
+ auto *MsgImm = cast<ConstantInt>(II.getArgOperand(0));
+ uint64_t Msg = MsgImm->getZExtValue();
+ // Extract the message ID. Pre-GFX11 uses the lower 4 bits, GFX11+ uses
+ // the lower 8 bits. Use 4-bit mask for extracting base message ID since
+ // all message types we handle fit in 4 bits, and the upper bits encode
+ // stream ID or other parameters for some message types (e.g., MSG_GS).
+ uint64_t MsgId = Msg & ID_MASK_PreGFX11_;
+
+ if (!msgDoesNotUseM0(MsgId, *ST))
+ break;
+
+ // Drop noundef attribute since we're replacing with poison.
+ II.removeParamAttr(1, Attribute::NoUndef);
----------------
arsenm wrote:
Maybe safer to use dropUBImplyingAttrsAndMetadata, in case that nopoison attribute ever gets added or something else
https://github.com/llvm/llvm-project/pull/183755
More information about the llvm-commits
mailing list