================
@@ -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
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to