[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
Tue May 27 13:53:35 PDT 2025
================
@@ -532,6 +541,89 @@ static Value *expandRadiansIntrinsic(CallInst *Orig) {
return Builder.CreateFMul(X, PiOver180);
}
+static Value *expandTypedBufferLoadIntrinsic(CallInst *Orig) {
+ IRBuilder<> Builder(Orig);
+
+ Type *BufferTy = Orig->getType()->getStructElementType(0);
+
+ unsigned ExtractNum = 2;
+ if (auto *VT = dyn_cast<FixedVectorType>(BufferTy)) {
+ assert(VT->getNumElements() == 2 &&
+ "TypedBufferLoad double vector has wrong size");
+ ExtractNum = 4;
+ }
+
+ Type *Ty = VectorType::get(Builder.getInt32Ty(), ExtractNum, false);
+
+ Type *LoadType = StructType::get(Ty, Builder.getInt1Ty());
+ CallInst *Load =
+ Builder.CreateIntrinsic(LoadType, Intrinsic::dx_resource_load_typedbuffer,
+ {Orig->getOperand(0), Orig->getOperand(1)});
+
+ // extract the buffer load's result
+ Value *Extract = Builder.CreateExtractValue(Load, {0});
+
+ SmallVector<Value *> ExtractElements;
+ for (unsigned I = 0; I < ExtractNum; ++I)
+ ExtractElements.push_back(
+ Builder.CreateExtractElement(Extract, (uint64_t)I));
----------------
bogner wrote:
Better to use the `i32` overloads of extractelement by creating the constant explicitly, rather than using the i64 helper.
```suggestion
ExtractElements.push_back(
Builder.CreateExtractElement(Extract, Builder.getInt32(I)));
```
This comes up a few times elsewhere with extract- and insertelement as well.
https://github.com/llvm/llvm-project/pull/139996
More information about the llvm-commits
mailing list