Skip to content

Commit 258a604

Browse files
committed
Use a feature, switch to G_TRAP
1 parent b575811 commit 258a604

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ def FeatureMSAALoadDstSelBug : SubtargetFeature<"msaa-load-dst-sel-bug",
303303
"MSAA loads not honoring dst_sel bug"
304304
>;
305305

306+
def FeaturePrivEnabledBug : SubtargetFeature<"priv-enabled-bug",
307+
"HasPrivEnabledBug",
308+
"true",
309+
"Hardware that runs with PRIV=1 workaround"
310+
>;
311+
306312
class SubtargetFeatureLDSBankCount <int Value> : SubtargetFeature <
307313
"ldsbankcount"#Value,
308314
"LDSBankCount",
@@ -1489,7 +1495,8 @@ def FeatureISAVersion11_0_Common : FeatureSet<
14891495
!listconcat(FeatureISAVersion11_Common.Features,
14901496
[FeatureMSAALoadDstSelBug,
14911497
FeatureVALUTransUseHazard,
1492-
FeatureMADIntraFwdBug])>;
1498+
FeatureMADIntraFwdBug,
1499+
FeaturePrivEnabledBug])>;
14931500

14941501
def FeatureISAVersion11_0_0 : FeatureSet<
14951502
!listconcat(FeatureISAVersion11_0_Common.Features,

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6727,7 +6727,9 @@ bool AMDGPULegalizerInfo::legalizeTrapHsaQueuePtr(
67276727
bool AMDGPULegalizerInfo::legalizeTrapHsa(MachineInstr &MI,
67286728
MachineRegisterInfo &MRI,
67296729
MachineIRBuilder &B) const {
6730-
if (ST.requiresSimulatedTrap()) {
6730+
// We need to simulate the 's_trap 2' instruction on targets that run in
6731+
// PRIV=1 (where it is treated as a nop).
6732+
if (ST.hasPrivEnabledBug()) {
67316733
ST.getInstrInfo()->insertSimulatedTrap(MRI, B.getMBB(), MI,
67326734
MI.getDebugLoc());
67336735
MI.eraseFromParent();

llvm/lib/Target/AMDGPU/GCNSubtarget.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "Utils/AMDGPUBaseInfo.h"
2424
#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
2525
#include "llvm/Support/ErrorHandling.h"
26-
#include "llvm/TargetParser/TargetParser.h"
2726

2827
#define GET_SUBTARGETINFO_HEADER
2928
#include "AMDGPUGenSubtargetInfo.inc"
@@ -224,6 +223,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
224223
bool HasImageStoreD16Bug = false;
225224
bool HasImageGather4D16Bug = false;
226225
bool HasMSAALoadDstSelBug = false;
226+
bool HasPrivEnabledBug = false;
227227
bool Has1_5xVGPRs = false;
228228
bool HasMADIntraFwdBug = false;
229229
bool HasVOPDInsts = false;
@@ -444,13 +444,6 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
444444
return isAmdHsaOS() ? TrapHandlerAbi::AMDHSA : TrapHandlerAbi::NONE;
445445
}
446446

447-
// True on hardware where 's_trap 2' is treated as a nop that must be
448-
// simulated.
449-
bool requiresSimulatedTrap() const {
450-
AMDGPU::IsaVersion V = AMDGPU::getIsaVersion(getCPU());
451-
return V.Major == 11 && V.Minor <= 3;
452-
}
453-
454447
bool supportsGetDoorbellID() const {
455448
// The S_GETREG DOORBELL_ID is supported by all GFX9 onward targets.
456449
return getGeneration() >= GFX9;
@@ -1034,6 +1027,8 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
10341027

10351028
bool hasMSAALoadDstSelBug() const { return HasMSAALoadDstSelBug; }
10361029

1030+
bool hasPrivEnabledBug() const { return HasPrivEnabledBug; }
1031+
10371032
bool hasNSAEncoding() const { return HasNSAEncoding; }
10381033

10391034
bool hasNonNSAEncoding() const { return getGeneration() < GFX12; }

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,7 +5410,7 @@ MachineBasicBlock *SITargetLowering::EmitInstrWithCustomInserter(
54105410
return SplitBB;
54115411
}
54125412
case AMDGPU::SIMULATED_TRAP: {
5413-
assert(Subtarget->requiresSimulatedTrap());
5413+
assert(Subtarget->hasPrivEnabledBug());
54145414
MachineRegisterInfo &MRI = BB->getParent()->getRegInfo();
54155415
MachineBasicBlock *SplitBB =
54165416
TII->insertSimulatedTrap(MRI, *BB, MI, MI.getDebugLoc());
@@ -6635,7 +6635,9 @@ SDValue SITargetLowering::lowerTrapHsa(
66356635
SDLoc SL(Op);
66366636
SDValue Chain = Op.getOperand(0);
66376637

6638-
if (Subtarget->requiresSimulatedTrap())
6638+
// We need to simulate the 's_trap 2' instruction on targets that run in
6639+
// PRIV=1 (where it is treated as a nop).
6640+
if (Subtarget->hasPrivEnabledBug())
66396641
return DAG.getNode(AMDGPUISD::SIMULATED_TRAP, SL, MVT::Other, Chain);
66406642

66416643
uint64_t TrapID = static_cast<uint64_t>(GCNSubtarget::TrapID::LLVMAMDHSATrap);

llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-trap-gfx11.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ body: |
4242
%0:_(s8) = G_CONSTANT i8 0
4343
%1:_(p1) = G_CONSTANT i64 0
4444
G_STORE %0, %1 :: (store 1, addrspace 1)
45-
G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.trap)
45+
G_TRAP
4646
G_STORE %0, %1 :: (store 1, addrspace 1)
4747
4848
...

0 commit comments

Comments
 (0)