Skip to content

Commit e9de91e

Browse files
[AMDGPU] Add safe-smem-prefetch SubtargetFeature off by default (#130050)
S_PREFETCH_* instructions may cause host to terminate process in case of the invalid address. Co-authored-by: Stanislav Mekhanoshin <[email protected]>
1 parent 180f803 commit e9de91e

File tree

6 files changed

+344
-232
lines changed

6 files changed

+344
-232
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ def FeatureInstFwdPrefetchBug : SubtargetFeature<"inst-fwd-prefetch-bug",
244244
"S_INST_PREFETCH instruction causes shader to hang"
245245
>;
246246

247+
def FeatureSafeSmemPrefetch : SubtargetFeature<"safe-smem-prefetch",
248+
"HasSafeSmemPrefetch",
249+
"true",
250+
"SMEM prefetches do not fail on illegal address"
251+
>;
252+
247253
def FeatureVcmpxExecWARHazard : SubtargetFeature<"vcmpx-exec-war-hazard",
248254
"HasVcmpxExecWARHazard",
249255
"true",

llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,7 @@ void AMDGPURegisterBankInfo::applyMappingImpl(
34603460
applyMappingMAD_64_32(B, OpdMapper);
34613461
return;
34623462
case AMDGPU::G_PREFETCH: {
3463-
if (!Subtarget.hasPrefetch()) {
3463+
if (!Subtarget.hasPrefetch() || !Subtarget.hasSafeSmemPrefetch()) {
34643464
MI.eraseFromParent();
34653465
return;
34663466
}

llvm/lib/Target/AMDGPU/GCNSubtarget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
233233
bool HasVMEMtoScalarWriteHazard = false;
234234
bool HasSMEMtoVectorWriteHazard = false;
235235
bool HasInstFwdPrefetchBug = false;
236+
bool HasSafeSmemPrefetch = false;
236237
bool HasVcmpxExecWARHazard = false;
237238
bool HasLdsBranchVmemWARHazard = false;
238239
bool HasNSAtoVMEMBug = false;
@@ -963,6 +964,8 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
963964

964965
bool hasPrefetch() const { return GFX12Insts; }
965966

967+
bool hasSafeSmemPrefetch() const { return HasSafeSmemPrefetch; }
968+
966969
// Has s_cmpk_* instructions.
967970
bool hasSCmpK() const { return getGeneration() < GFX12; }
968971

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM,
855855
if (Subtarget->hasMad64_32())
856856
setOperationAction({ISD::SMUL_LOHI, ISD::UMUL_LOHI}, MVT::i32, Custom);
857857

858-
if (Subtarget->hasPrefetch())
858+
if (Subtarget->hasPrefetch() && Subtarget->hasSafeSmemPrefetch())
859859
setOperationAction(ISD::PREFETCH, MVT::Other, Custom);
860860

861861
if (Subtarget->hasIEEEMinMax()) {

0 commit comments

Comments
 (0)