[llvm-branch-commits] [clang] [llvm] [AMDGPU] Canonicalize num_records to its actual width in InstCombine (PR #217068)

Lukas Sommer via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 25 02:14:33 PDT 2026


================
@@ -2177,7 +2177,27 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
     Value *Src = II.getArgOperand(0);
     if (isa<PoisonValue>(Src))
       return IC.replaceInstUsesWith(II, PoisonValue::get(II.getType()));
-    return std::nullopt;
+
+    // Normalize num_records to the correct width.
+    std::optional<unsigned> Width = ST->getBufferResourceNumRecordsWidth();
+    if (!Width)
+      return std::nullopt;
+    Type *NumRecordsTy = IC.Builder.getIntNTy(*Width);
+    if (II.getArgOperand(2)->getType() == NumRecordsTy)
+      return std::nullopt;
+    SmallVector<Value *, 4> Args(II.args());
+    Args[2] = IC.Builder.CreateZExtOrTrunc(Args[2], NumRecordsTy);
+    CallInst *NewCall = IC.Builder.CreateIntrinsicWithoutFolding(
+        Intrinsic::amdgcn_make_buffer_rsrc,
+        {II.getType(), Src->getType(), NumRecordsTy}, Args);
----------------
sommerlukas wrote:

Do we need to take care of operand bundles here? If so, we should probably also have a test for it. 

https://github.com/llvm/llvm-project/pull/217068


More information about the llvm-branch-commits mailing list