[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferLoad` to DXIL ops (PR #104252)
David Peixotto via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 20 12:03:59 PDT 2024
================
@@ -236,6 +236,59 @@ class OpLowerer {
lowerToBindAndAnnotateHandle(F);
}
+ void lowerTypedBufferLoad(Function &F) {
+ IRBuilder<> &IRB = OpBuilder.getIRB();
+ Type *Int32Ty = IRB.getInt32Ty();
+
+ replaceFunction(F, [&](CallInst *CI) -> Error {
+ IRB.SetInsertPoint(CI);
+
+ Value *Handle =
+ createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
+ Value *Index0 = CI->getArgOperand(1);
+ Value *Index1 = UndefValue::get(Int32Ty);
+ Type *RetTy = OpBuilder.getResRetType(CI->getType()->getScalarType());
+
+ std::array<Value *, 3> Args{Handle, Index0, Index1};
+ Expected<CallInst *> OpCall =
+ OpBuilder.tryCreateOp(OpCode::BufferLoad, Args, RetTy);
+ if (Error E = OpCall.takeError())
+ return E;
+
+ std::array<Value *, 4> Extracts = {};
+
+ // We've switched the return type from a vector to a struct, but at this
+ // point most vectors have probably already been scalarized. Try to
+ // forward arguments directly rather than inserting into and immediately
+ // extracting from a vector.
+ for (Use &U : make_early_inc_range(CI->uses()))
+ if (auto *EEI = dyn_cast<ExtractElementInst>(U.getUser()))
+ if (auto *Index = dyn_cast<ConstantInt>(EEI->getIndexOperand())) {
+ size_t IndexVal = Index->getZExtValue();
+ assert(IndexVal < 4 && "Index into buffer load out of range");
----------------
dmpots wrote:
Have we thought about how `CheckAccessFullyMapped` is going to fit into this scheme? In dxil, that will lower to an extract of index 4 on the `dx.types.ResRet` struct.
https://github.com/llvm/llvm-project/pull/104252
More information about the llvm-branch-commits
mailing list