
Currently, we use `AAAMDWavesPerEU` to iteratively update values based on attributes from the associated function, potentially propagating user-annotated values, along with `AAAMDFlatWorkGroupSize`. Similarly, we have `AAAMDFlatWorkGroupSize`. However, since the value calculated through the flat workgroup size always dominates the user annotation (i.e., the attribute), running `AAAMDWavesPerEU` iteratively is unnecessary if no user-annotated value exists. This PR completely rewrites how the `amdgpu-waves-per-eu` attribute is handled in `AMDGPUAttributor`. The key changes are as follows: - `AAAMDFlatWorkGroupSize` remains unchanged. - `AAAMDWavesPerEU` now only propagates user-annotated values. - A new function is added to check and update `amdgpu-waves-per-eu` based on the following rules: - No waves per eu, no flat workgroup size: Assume a flat workgroup size of `1,1024` and compute waves per eu based on this. - No waves per eu, flat workgroup size exists: Use the provided flat workgroup size to compute waves-per-eu. - Waves per eu exists, no flat workgroup size: This is a tricky case. In this PR, we assume a flat workgroup size of `1,1024`, but this can be adjusted if a different approach is preferred. Alternatively, we could directly use the user-annotated value. - Both waves per eu and flat workgroup size exist: If there’s a conflict, the value derived from the flat workgroup size takes precedence over waves per eu. This PR also updates the logic for merging two waves per eu pairs. The current implementation, which uses `clampStateAndIndicateChange` to compute a union, might not be ideal. If we think from ensure proper resource allocation perspective, for instance, if one pair specifies a minimum of 2 waves per eu, and another specifies a minimum of 4, we should guarantee that 4 waves per eu can be supported, as failing to do so could result in excessive resource allocation per wave. A similar principle applies to the upper bound. Thus, the PR uses the following approach for merging two pairs, `lo_a,up_a` and `lo_b,up_b`: `max(lo_a, lo_b), max(up_a, up_b)`. This ensures that resource allocation adheres to the stricter constraints from both inputs. Fix #123092.
175 lines
11 KiB
LLVM
175 lines
11 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals
|
|
; RUN: opt -mtriple=amdgcn-unknown-amdhsa -S -passes=amdgpu-attributor < %s | FileCheck -check-prefix=HSA %s
|
|
|
|
declare void @llvm.memcpy.p1.p4.i32(ptr addrspace(1) nocapture, ptr addrspace(4) nocapture, i32, i1) #0
|
|
|
|
@lds.i32 = unnamed_addr addrspace(3) global i32 poison, align 4
|
|
@lds.arr = unnamed_addr addrspace(3) global [256 x i32] poison, align 4
|
|
|
|
@global.i32 = unnamed_addr addrspace(1) global i32 poison, align 4
|
|
@global.arr = unnamed_addr addrspace(1) global [256 x i32] poison, align 4
|
|
|
|
;.
|
|
; HSA: @lds.i32 = unnamed_addr addrspace(3) global i32 poison, align 4
|
|
; HSA: @lds.arr = unnamed_addr addrspace(3) global [256 x i32] poison, align 4
|
|
; HSA: @global.i32 = unnamed_addr addrspace(1) global i32 poison, align 4
|
|
; HSA: @global.arr = unnamed_addr addrspace(1) global [256 x i32] poison, align 4
|
|
;.
|
|
define amdgpu_kernel void @store_cast_0_flat_to_group_addrspacecast() #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_cast_0_flat_to_group_addrspacecast
|
|
; HSA-SAME: () #[[ATTR1:[0-9]+]] {
|
|
; HSA-NEXT: store i32 7, ptr addrspace(3) addrspacecast (ptr addrspace(4) null to ptr addrspace(3)), align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store i32 7, ptr addrspace(3) addrspacecast (ptr addrspace(4) null to ptr addrspace(3))
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @store_cast_0_group_to_flat_addrspacecast() #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_cast_0_group_to_flat_addrspacecast
|
|
; HSA-SAME: () #[[ATTR2:[0-9]+]] {
|
|
; HSA-NEXT: store i32 7, ptr addrspace(4) addrspacecast (ptr addrspace(3) null to ptr addrspace(4)), align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store i32 7, ptr addrspace(4) addrspacecast (ptr addrspace(3) null to ptr addrspace(4))
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @store_constant_cast_group_gv_to_flat() #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_constant_cast_group_gv_to_flat
|
|
; HSA-SAME: () #[[ATTR2]] {
|
|
; HSA-NEXT: store i32 7, ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.i32 to ptr addrspace(4)), align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store i32 7, ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.i32 to ptr addrspace(4))
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @store_constant_cast_group_gv_gep_to_flat() #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_constant_cast_group_gv_gep_to_flat
|
|
; HSA-SAME: () #[[ATTR2]] {
|
|
; HSA-NEXT: store i32 7, ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store i32 7, ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8)
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @store_constant_cast_global_gv_to_flat() #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_constant_cast_global_gv_to_flat
|
|
; HSA-SAME: () #[[ATTR1]] {
|
|
; HSA-NEXT: store i32 7, ptr addrspace(4) addrspacecast (ptr addrspace(1) @global.i32 to ptr addrspace(4)), align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store i32 7, ptr addrspace(4) addrspacecast (ptr addrspace(1) @global.i32 to ptr addrspace(4))
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @store_constant_cast_global_gv_gep_to_flat() #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_constant_cast_global_gv_gep_to_flat
|
|
; HSA-SAME: () #[[ATTR1]] {
|
|
; HSA-NEXT: store i32 7, ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(1) @global.arr to ptr addrspace(4)), i64 0, i64 8), align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store i32 7, ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(1) @global.arr to ptr addrspace(4)), i64 0, i64 8)
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @load_constant_cast_group_gv_gep_to_flat(ptr addrspace(1) %out) #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@load_constant_cast_group_gv_gep_to_flat
|
|
; HSA-SAME: (ptr addrspace(1) [[OUT:%.*]]) #[[ATTR2]] {
|
|
; HSA-NEXT: [[VAL:%.*]] = load i32, ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), align 4
|
|
; HSA-NEXT: store i32 [[VAL]], ptr addrspace(1) [[OUT]], align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
%val = load i32, ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8)
|
|
store i32 %val, ptr addrspace(1) %out
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @atomicrmw_constant_cast_group_gv_gep_to_flat(ptr addrspace(1) %out) #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@atomicrmw_constant_cast_group_gv_gep_to_flat
|
|
; HSA-SAME: (ptr addrspace(1) [[OUT:%.*]]) #[[ATTR2]] {
|
|
; HSA-NEXT: [[VAL:%.*]] = atomicrmw add ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), i32 1 seq_cst, align 4
|
|
; HSA-NEXT: store i32 [[VAL]], ptr addrspace(1) [[OUT]], align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
%val = atomicrmw add ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), i32 1 seq_cst
|
|
store i32 %val, ptr addrspace(1) %out
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @cmpxchg_constant_cast_group_gv_gep_to_flat(ptr addrspace(1) %out) #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@cmpxchg_constant_cast_group_gv_gep_to_flat
|
|
; HSA-SAME: (ptr addrspace(1) [[OUT:%.*]]) #[[ATTR2]] {
|
|
; HSA-NEXT: [[VAL:%.*]] = cmpxchg ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), i32 0, i32 1 seq_cst seq_cst, align 4
|
|
; HSA-NEXT: [[VAL0:%.*]] = extractvalue { i32, i1 } [[VAL]], 0
|
|
; HSA-NEXT: store i32 [[VAL0]], ptr addrspace(1) [[OUT]], align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
%val = cmpxchg ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), i32 0, i32 1 seq_cst seq_cst
|
|
%val0 = extractvalue { i32, i1 } %val, 0
|
|
store i32 %val0, ptr addrspace(1) %out
|
|
ret void
|
|
}
|
|
|
|
define amdgpu_kernel void @memcpy_constant_cast_group_gv_gep_to_flat(ptr addrspace(1) %out) #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@memcpy_constant_cast_group_gv_gep_to_flat
|
|
; HSA-SAME: (ptr addrspace(1) [[OUT:%.*]]) #[[ATTR2]] {
|
|
; HSA-NEXT: call void @llvm.memcpy.p1.p4.i32(ptr addrspace(1) align 4 [[OUT]], ptr addrspace(4) align 4 getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), i32 32, i1 false)
|
|
; HSA-NEXT: ret void
|
|
;
|
|
call void @llvm.memcpy.p1.p4.i32(ptr addrspace(1) align 4 %out, ptr addrspace(4) align 4 getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), i32 32, i1 false)
|
|
ret void
|
|
}
|
|
|
|
; Can't just search the pointer value
|
|
define amdgpu_kernel void @store_value_constant_cast_lds_gv_gep_to_flat(ptr addrspace(1) %out) #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_value_constant_cast_lds_gv_gep_to_flat
|
|
; HSA-SAME: (ptr addrspace(1) [[OUT:%.*]]) #[[ATTR2]] {
|
|
; HSA-NEXT: store ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), ptr addrspace(1) [[OUT]], align 8
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8), ptr addrspace(1) %out
|
|
ret void
|
|
}
|
|
|
|
; Can't just search pointer types
|
|
define amdgpu_kernel void @store_ptrtoint_value_constant_cast_lds_gv_gep_to_flat(ptr addrspace(1) %out) #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_ptrtoint_value_constant_cast_lds_gv_gep_to_flat
|
|
; HSA-SAME: (ptr addrspace(1) [[OUT:%.*]]) #[[ATTR2]] {
|
|
; HSA-NEXT: store i64 ptrtoint (ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8) to i64), ptr addrspace(1) [[OUT]], align 8
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store i64 ptrtoint (ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8) to i64), ptr addrspace(1) %out
|
|
ret void
|
|
}
|
|
|
|
; Cast group to flat, do GEP, cast back to group
|
|
define amdgpu_kernel void @store_constant_cast_group_gv_gep_to_flat_to_group() #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@store_constant_cast_group_gv_gep_to_flat_to_group
|
|
; HSA-SAME: () #[[ATTR2]] {
|
|
; HSA-NEXT: store i32 7, ptr addrspace(3) addrspacecast (ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8) to ptr addrspace(3)), align 4
|
|
; HSA-NEXT: ret void
|
|
;
|
|
store i32 7, ptr addrspace(3) addrspacecast (ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8) to ptr addrspace(3))
|
|
ret void
|
|
}
|
|
|
|
define ptr addrspace(3) @ret_constant_cast_group_gv_gep_to_flat_to_group() #1 {
|
|
; HSA-LABEL: define {{[^@]+}}@ret_constant_cast_group_gv_gep_to_flat_to_group
|
|
; HSA-SAME: () #[[ATTR2]] {
|
|
; HSA-NEXT: ret ptr addrspace(3) addrspacecast (ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8) to ptr addrspace(3))
|
|
;
|
|
ret ptr addrspace(3) addrspacecast (ptr addrspace(4) getelementptr ([256 x i32], ptr addrspace(4) addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4)), i64 0, i64 8) to ptr addrspace(3))
|
|
}
|
|
|
|
attributes #0 = { argmemonly nounwind }
|
|
attributes #1 = { nounwind }
|
|
|
|
;.
|
|
; HSA: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
|
|
; HSA: attributes #[[ATTR1]] = { nounwind "amdgpu-agpr-alloc"="0" "amdgpu-no-completion-action" "amdgpu-no-default-queue" "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-flat-scratch-init" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-ptr" "amdgpu-no-lds-kernel-id" "amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" "amdgpu-waves-per-eu"="4,10" "uniform-work-group-size"="false" }
|
|
; HSA: attributes #[[ATTR2]] = { nounwind "amdgpu-agpr-alloc"="0" "amdgpu-no-completion-action" "amdgpu-no-default-queue" "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-flat-scratch-init" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-lds-kernel-id" "amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" "amdgpu-waves-per-eu"="4,10" "uniform-work-group-size"="false" }
|
|
;.
|