Skip to content

Commit eae55db

Browse files
committed
AMDGPU: Ensure both wavesize features are not set
Make sure we cannot be in a mode with both wavesizes. This prevents assertions in a future change. This should probably just be an error, but we do not have a good way to report errors from the MCSubtargetInfo constructor. This breaks the assembler test which enables both, but this behavior is not really useful. Maybe it's better to just delete the test.
1 parent a38794f commit eae55db

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,32 @@ createAMDGPUMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
8282
MCSubtargetInfo *STI =
8383
createAMDGPUMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
8484

85+
bool IsWave64 = STI->hasFeature(AMDGPU::FeatureWavefrontSize64);
86+
bool IsWave32 = STI->hasFeature(AMDGPU::FeatureWavefrontSize32);
87+
8588
// FIXME: We should error for the default target.
8689
if (STI->getFeatureBits().none())
8790
STI->ToggleFeature(AMDGPU::FeatureSouthernIslands);
8891

89-
if (!STI->hasFeature(AMDGPU::FeatureWavefrontSize64) &&
90-
!STI->hasFeature(AMDGPU::FeatureWavefrontSize32)) {
92+
if (!IsWave64 && !IsWave32) {
9193
// If there is no default wave size it must be a generation before gfx10,
9294
// these have FeatureWavefrontSize64 in their definition already. For gfx10+
9395
// set wave32 as a default.
9496
STI->ToggleFeature(AMDGPU::isGFX10Plus(*STI)
9597
? AMDGPU::FeatureWavefrontSize32
9698
: AMDGPU::FeatureWavefrontSize64);
99+
} else if (IsWave64 && IsWave32) {
100+
// The wave size is mutually exclusive. If both somehow end up set, wave64
101+
// wins.
102+
//
103+
// FIXME: This should really just be an error.
104+
STI->ToggleFeature(AMDGPU::FeatureWavefrontSize32);
97105
}
98106

107+
assert((STI->hasFeature(AMDGPU::FeatureWavefrontSize64) ^
108+
STI->hasFeature(AMDGPU::FeatureWavefrontSize32)) &&
109+
"wavesize features are mutually exclusive");
110+
99111
return STI;
100112
}
101113

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: llvm-mc -triple=amdgcn -mcpu=gfx1250 -mattr=+wavefrontsize64 -o - %s | FileCheck -check-prefix=GFX1250 %s
2+
// RUN: llvm-mc -triple=amdgcn -mcpu=gfx900 -mattr=+wavefrontsize32 -o - %s | FileCheck -check-prefix=GFX900 %s
3+
4+
// Both are supported, but not at the same time
5+
// RUN: llvm-mc -triple=amdgcn -mcpu=gfx1010 -mattr=+wavefrontsize32,+wavefrontsize64 %s | FileCheck -check-prefixes=GFX10 %s
6+
7+
// Test that there is no assertion when using an explicit
8+
// wavefrontsize attribute on a target which does not support it.
9+
10+
// GFX1250: v_add_f64_e32 v[0:1], 1.0, v[0:1]
11+
// GFX900: v_add_f64 v[0:1], 1.0, v[0:1]
12+
// GFX10: v_add_f64 v[0:1], 1.0, v[0:1]
13+
v_add_f64 v[0:1], 1.0, v[0:1]
14+
15+
// GFX1250: v_cmp_eq_u32_e64 s[0:1], 1.0, s1
16+
// GFX900: v_cmp_eq_u32_e64 s[0:1], 1.0, s1
17+
// GFX10: v_cmp_eq_u32_e64 s[0:1], 1.0, s1
18+
v_cmp_eq_u32_e64 s[0:1], 1.0, s1
19+
20+
// GFX1250: v_cndmask_b32_e64 v1, v2, v3, s[0:1]
21+
// GFX900: v_cndmask_b32_e64 v1, v2, v3, s[0:1]
22+
// GFX10: v_cndmask_b32_e64 v1, v2, v3, s[0:1]
23+
v_cndmask_b32 v1, v2, v3, s[0:1]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1250 -mattr=+wavefrontsize64 -disassemble -o - %s | FileCheck %s
2+
3+
# Make sure there's no assertion when trying to use an unsupported
4+
# wave64 on a wave32-only target
5+
6+
# CHECK: v_add_f64_e32 v[0:1], 1.0, v[0:1]
7+
0xf2,0x00,0x00,0x04
8+
9+
# CHECK: v_cmp_eq_u32_e64 s[0:1], 1.0, s1
10+
0x00,0x00,0x4a,0xd4,0xf2,0x02,0x00,0x00
11+
12+
# CHECK: v_cndmask_b32_e64 v1, v2, v3, s[0:1]
13+
0x01,0x00,0x01,0xd5,0x02,0x07,0x02,0x00
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx900 -mattr=+wavefrontsize32 -disassemble -o - %s | FileCheck %s
2+
3+
# Make sure there's no assertion when trying to use an unsupported
4+
# wave32 on a wave64-only target
5+
6+
# CHECK: v_add_f64 v[0:1], 1.0, v[0:1]
7+
0x00,0x00,0x80,0xd2,0xf2,0x00,0x02,0x00
8+
9+
# CHECK: v_cmp_eq_u32_e64 s[0:1], 1.0, s1
10+
0x00,0x00,0xca,0xd0,0xf2,0x02,0x00,0x00
11+
12+
# CHECK: v_cndmask_b32_e64 v1, v2, v3, s[0:1]
13+
0x01,0x00,0x00,0xd1,0x02,0x07,0x02,0x00

0 commit comments

Comments
 (0)