[llvm] [DirectX] Add support for typedBufferLoad and Store for RWBuffer<double2> and RWBuffer<double> (PR #139996)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 22:04:46 PDT 2025
================
@@ -532,6 +541,80 @@ static Value *expandRadiansIntrinsic(CallInst *Orig) {
return Builder.CreateFMul(X, PiOver180);
}
+static void expandTypedBufferLoadIntrinsic(CallInst *Orig) {
+ IRBuilder<> Builder(Orig);
+
+ unsigned ExtractNum =
+ Orig->getType()->getStructElementType(0)->isVectorTy() ? 4 : 2;
+ Type *Ty = VectorType::get(Builder.getInt32Ty(), ExtractNum, false);
+
+ Type *LoadType = StructType::get(Ty, Builder.getInt1Ty());
+ auto *X =
+ Builder.CreateIntrinsic(LoadType, Intrinsic::dx_resource_load_typedbuffer,
+ {Orig->getOperand(0), Orig->getOperand(1)});
+
+ // create new extract value
+ Value *Extract = Builder.CreateExtractValue(X, {0});
+
+ SmallVector<Value *> ExtractElements;
+ for (unsigned I = 0; I < ExtractNum; ++I)
+ ExtractElements.push_back(
+ Builder.CreateExtractElement(Extract, (uint64_t)I));
+
+ // combine into double(s)
+ Value *Result =
+ PoisonValue::get(VectorType::get(Builder.getDoubleTy(), 2, false));
+ for (unsigned I = 0; I < ExtractNum; I += 2) {
+ Value *Dbl =
+ Builder.CreateIntrinsic(Builder.getDoubleTy(), Intrinsic::dx_asdouble,
+ {ExtractElements[I], ExtractElements[I + 1]});
+ if (ExtractNum == 4)
+ Result = Builder.CreateInsertElement(Result, Dbl, (uint64_t)I / 2);
+ else
+ Result = Dbl;
+ }
+
+ assert(Orig->hasOneUser() && "TypedBufferLoad is expected to have one user");
+ auto *U = Orig->user_back();
+ auto *OldExtract = dyn_cast<ExtractValueInst>(U);
+ if (!OldExtract)
+ llvm_unreachable("TypedBufferLoad's only users should be ExtractValueInst");
+ OldExtract->replaceAllUsesWith(Result);
+ OldExtract->eraseFromParent();
+}
+
+void expandTypedBufferStoreIntrinsic(CallInst *Orig) {
+ IRBuilder<> Builder(Orig);
+
+ unsigned ExtractNum =
+ Orig->getFunctionType()->getParamType(2)->isVectorTy() ? 4 : 2;
+ Type *SplitElementTy = Builder.getInt32Ty();
+ SmallVector<int> Mask = {0, 1};
----------------
bogner wrote:
Is this used?
https://github.com/llvm/llvm-project/pull/139996
More information about the llvm-commits
mailing list