Skip to content

Commit 23402ab

Browse files
stefan-iligcbot
authored andcommitted
Fix merging of uniform and non-uniform allocas
Merging between uniform and non-uniform allocas was creating incorrect address calculation since simdLaneId was being ignored for non-uniform values.
1 parent 5e6b681 commit 23402ab

File tree

7 files changed

+38
-11
lines changed

7 files changed

+38
-11
lines changed

IGC/AdaptorCommon/LivenessUtils/MergeAllocas.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ static MergeAllocas::AllocaInfo GetAllocaInfo(AllocaInst *allocaI,
5050
allocationSize,
5151
static_cast<size_t>(
5252
DL->getPrefTypeAlign(allocaI->getAllocatedType()).value()),
53-
0};
53+
0,
54+
allocaI->getMetadata("uniform") != nullptr};
5455
}
5556

5657
static size_t GetStartingOffset(size_t startOffset, size_t alignment) {
@@ -63,6 +64,9 @@ static size_t GetStartingOffset(size_t startOffset, size_t alignment) {
6364

6465
static bool AddNonOverlappingAlloca(MergeAllocas::AllocaInfo* MergableAlloca,
6566
MergeAllocas::AllocaInfo* NewAlloca) {
67+
if (MergableAlloca->isUniform != NewAlloca->isUniform) {
68+
return false;
69+
}
6670
if (MergableAlloca->addressSpace != NewAlloca->addressSpace) {
6771
return false;
6872
}

IGC/AdaptorCommon/LivenessUtils/MergeAllocas.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace IGC
3434
std::size_t alignment;
3535
// start offset of this alloca in top level alloca (if any)
3636
std::size_t offset;
37+
bool isUniform;
3738
};
3839

3940
MergeAllocas(char& pid) : AllocationLivenessAnalyzer(pid) {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
; RUN: igc_opt --igc-ocl-merge-allocas -S %s --platformpvc | FileCheck %s
9+
; ------------------------------------------------
10+
; MergeAllocas
11+
; ------------------------------------------------
12+
13+
; Check that allocas are not merged if they are not both uniform or non-uniform.
14+
define spir_kernel void @testFn() {
15+
; CHECK-LABEL: testFn
16+
; CHECK-NEXT: alloca [128 x float], i32 0, align 4
17+
; CHECK-NEXT: alloca [128 x float], i32 0, align 4
18+
%1 = alloca [128 x float], i32 0, align 4, !uniform !0
19+
%2 = alloca [128 x float], i32 0, align 4
20+
ret void
21+
}
22+
!0 = !{i1 true}

IGC/Compiler/tests/PrivateMemoryResolution/MergeAllocas/merge_allocas.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ declare void @llvm.assume(i1 noundef) #1
2424

2525
declare spir_func void @__itt_offload_wi_finish_wrapper()
2626

27-
define spir_kernel void @_ZTS43Kernel_NoReusePrivMem_SameFunc_AlwaysInline(float addrspace(1)* %0, i64 %1, i64 %2, i32 %3, i32 %4, i32 %5) {
28-
; CHECK-LABEL: _ZTS43Kernel_NoReusePrivMem_SameFunc_AlwaysInline
27+
define spir_kernel void @main(float addrspace(1)* %0, i64 %1, i64 %2, i32 %3, i32 %4, i32 %5) {
28+
; CHECK-LABEL: main
2929
; CHECK-NEXT: alloca [128 x float], align 4
3030
; CHECK-NOT: alloca [128 x float], align 4
3131
%7 = alloca [128 x float], align 4

IGC/Compiler/tests/PrivateMemoryResolution/MergeAllocas/merge_allocas_loop.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
2121
declare void @llvm.memcpy.p4i8.p4i8.i64(i8 addrspace(4)* noalias nocapture writeonly, i8 addrspace(4)* noalias nocapture readonly, i64, i1 immarg) #1
2222

2323
; Function Attrs: noinline optnone
24-
define internal spir_func i1 @_ZN12_GLOBAL__N_117check_elems_equalIdLi3EEEbRKN4sycl3_V13vecIT_XT0_EEES7_.28(i1 %0) #2 {
24+
define internal spir_func i1 @testFn(i1 %0) #2 {
2525
%2 = alloca %"class.sycl::_V1::vec.73", i32 0, align 32
2626
%3 = addrspacecast %"class.sycl::_V1::vec.73"* null to %"class.sycl::_V1::vec.73" addrspace(4)*
2727
br label %4
@@ -45,8 +45,8 @@ define internal spir_func i1 @_ZN12_GLOBAL__N_117check_elems_equalIdLi3EEEbRKN4s
4545
ret i1 false
4646
}
4747

48-
define spir_kernel void @_ZTSN16accessor_utility34buffer_accessor_get_pointer_kernelIN25accessor_api_local_fp64__11kernel_nameIN4sycl3_V13vecIdLi3EEEEELi0ELNS4_6access4modeE1026ELNS8_6targetE2016ELNS8_11placeholderE0EEE() {
49-
%1 = call spir_func i1 @_ZN12_GLOBAL__N_117check_elems_equalIdLi3EEEbRKN4sycl3_V13vecIT_XT0_EEES7_.28(i1 undef)
48+
define spir_kernel void @main() {
49+
%1 = call spir_func i1 @testFn(i1 undef)
5050
ret void
5151
}
5252

IGC/Compiler/tests/PrivateMemoryResolution/MergeAllocas/merge_allocas_loop2.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ target triple = "spir64-unknown-unknown"
1919
%"class.sycl::_V1::vec.73" = type { <3 x double> }
2020

2121
; Function Attrs: noinline optnone
22-
define internal spir_func i1 @_ZN12_GLOBAL__N_117check_elems_equalIdLi3EEEbRKN4sycl3_V13vecIT_XT0_EEES7_.28() #0 {
22+
define internal spir_func i1 @testFn() #0 {
2323
%1 = alloca %"class.sycl::_V1::vec.73", i32 0, align 32
2424
br label %2
2525

@@ -39,8 +39,8 @@ define internal spir_func i1 @_ZN12_GLOBAL__N_117check_elems_equalIdLi3EEEbRKN4s
3939
ret i1 false
4040
}
4141

42-
define spir_kernel void @_ZTSN16accessor_utility34buffer_accessor_get_pointer_kernelIN25accessor_api_local_fp64__11kernel_nameIN4sycl3_V13vecIdLi3EEEEELi0ELNS4_6access4modeE1026ELNS8_6targetE2016ELNS8_11placeholderE0EEE() {
43-
%1 = call spir_func i1 @_ZN12_GLOBAL__N_117check_elems_equalIdLi3EEEbRKN4sycl3_V13vecIT_XT0_EEES7_.28()
42+
define spir_kernel void @main() {
43+
%1 = call spir_func i1 @testFn()
4444
ret void
4545
}
4646

IGC/Compiler/tests/PrivateMemoryResolution/MergeAllocas/merge_allocas_optnone.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
; Check that allocas are not merged if optnone attribute is set
1414
; Function Attrs: noinline optnone
15-
define spir_kernel void @_ZTS43Kernel_NoReusePrivMem_SameFunc_AlwaysInline() #0 {
16-
; CHECK-LABEL: _ZTS43Kernel_NoReusePrivMem_SameFunc_AlwaysInline
15+
define spir_kernel void @testFn() #0 {
16+
; CHECK-LABEL: testFn
1717
; CHECK-NEXT: alloca [128 x float], i32 0, align 4
1818
; CHECK-NEXT: alloca [128 x float], i32 0, align 4
1919
%1 = alloca [128 x float], i32 0, align 4

0 commit comments

Comments
 (0)