Skip to content

Commit 8cc846b

Browse files
committed
address Justin
1 parent 0d0b79f commit 8cc846b

File tree

4 files changed

+19
-30
lines changed

4 files changed

+19
-30
lines changed

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
365365
const HLSLAttributedResourceType *RT =
366366
HandleTy->getAs<HLSLAttributedResourceType>();
367367
assert(RT && "Expected a resource type as first parameter");
368+
assert(CGM.getTarget().getTriple().getArch() == llvm::Triple::dxil &&
369+
"Only DXIL currently implements load with status");
368370

369371
Intrinsic::ID IntrID = RT->getAttrs().RawBuffer
370372
? llvm::Intrinsic::dx_resource_load_rawbuffer
@@ -379,24 +381,25 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
379381
Args.push_back(IndexOp);
380382

381383
if (RT->getAttrs().RawBuffer) {
382-
Args.push_back(Builder.getInt32(0)); // dummy offset
384+
Value *Offset = Builder.getInt32(0);
385+
Args.push_back(Offset);
383386
}
384387

385-
// Call the intrinsic (returns a struct)
388+
// Call the intrinsic (returns a struct),
389+
// Extract the loaded value and status bit (elements within the struct)
390+
// Extend the status bit to a 32-bit integer
391+
// Store the extended status into the user's reference variable
392+
// Return the loaded value
386393
Value *ResRet =
387394
Builder.CreateIntrinsic(RetTy, IntrID, Args, {}, "ld.struct");
388395

389-
// Extract the loaded data (first element of the struct)
390396
Value *LoadedValue = Builder.CreateExtractValue(ResRet, {0}, "ld.value");
391397

392-
// Extract the status bit (second element of the struct)
393398
Value *StatusBit = Builder.CreateExtractValue(ResRet, {1}, "ld.status");
394399

395-
// Extend the status bit to a 32-bit integer
396400
Value *ExtendedStatus =
397401
Builder.CreateZExt(StatusBit, Builder.getInt32Ty(), "ld.status.ext");
398402

399-
// Store the extended status into the user's reference variable
400403
Builder.CreateStore(ExtendedStatus, StatusAddr);
401404

402405
return LoadedValue;

llvm/include/llvm/IR/IntrinsicsDirectX.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ def int_dx_resource_getpointer
4040
: DefaultAttrsIntrinsic<[llvm_anyptr_ty], [llvm_any_ty, llvm_i32_ty],
4141
[IntrNoMem]>;
4242

43-
def int_dx_resource_load_with_status
44-
: DefaultAttrsIntrinsic<[llvm_anyptr_ty], [llvm_any_ty, llvm_i32_ty, llvm_i32_ty],
45-
[IntrNoMem]>;
46-
4743
def int_dx_resource_nonuniformindex
4844
: DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty], [IntrNoMem]>;
4945

llvm/lib/Target/DirectX/DXILOpLowering.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,6 @@ class OpLowerer {
657657
return false;
658658
}
659659

660-
[[nodiscard]] bool lowerLoadWithStatus(Function &F) {
661-
// These should have already been handled in DXILResourceAccess, so we can
662-
// just clean up the dead prototype.
663-
assert(F.user_empty() && "getpointer operations should have been removed");
664-
F.eraseFromParent();
665-
return false;
666-
}
667-
668660
[[nodiscard]] bool lowerBufferStore(Function &F, bool IsRaw) {
669661
const DataLayout &DL = F.getDataLayout();
670662
IRBuilder<> &IRB = OpBuilder.getIRB();
@@ -941,9 +933,6 @@ class OpLowerer {
941933
case Intrinsic::dx_resource_getpointer:
942934
HasErrors |= lowerGetPointer(F);
943935
break;
944-
case Intrinsic::dx_resource_load_with_status:
945-
HasErrors |= lowerLoadWithStatus(F);
946-
break;
947936
case Intrinsic::dx_resource_nonuniformindex:
948937
assert(!CleanupNURI &&
949938
"overloaded llvm.dx.resource.nonuniformindex intrinsics?");

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,17 @@ static bool checkWaveOps(Intrinsic::ID IID) {
105105
// This is our proof that the module requires TiledResources
106106
// to be set, as if check access fully mapped was used.
107107
bool checkIfStatusIsExtracted(const Instruction &I) {
108-
// Iterate over all uses of the instruction
109-
for (const Use &U : I.uses()) {
110-
const User *UserInst = U.getUser();
111-
112-
// Check if the user is an ExtractValue instruction
113-
if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(UserInst)) {
114-
// ExtractValueInst has a list of indices; check if it extracts index 1
115-
if (EVI->getNumIndices() == 1 && EVI->getIndices()[0] == 1) {
108+
auto *II = dyn_cast<IntrinsicInst>(&I);
109+
assert(II);
110+
auto IID = II->getIntrinsicID();
111+
assert(IID == Intrinsic::dx_resource_load_typedbuffer ||
112+
IID == Intrinsic::dx_resource_load_rawbuffer);
113+
for (const User *U : I.users()) {
114+
if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(U)) {
115+
// Resource load operations return a {result, status} pair
116+
// check if we extract the status
117+
if (EVI->getNumIndices() == 1 && EVI->getIndices()[0] == 1)
116118
return true;
117-
}
118119
}
119120
}
120121

0 commit comments

Comments
 (0)