Skip to content

Commit 27aca1c

Browse files
stefan-iligcbot
authored andcommitted
Add flag to disable merging allocas of different types
Adds flag for better control of merge alloca pass. Also disable more aggresive merging as being default.
1 parent 979782a commit 27aca1c

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

IGC/AdaptorCommon/RayTracing/MergeAllocas.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ static bool AddNonOverlappingAlloca(AllocaInfo *MergableAlloca,
8080
return false;
8181
}
8282

83+
if (IGC_IS_FLAG_ENABLED(DisableMergingOfAllocasWithDifferentType))
84+
{
85+
auto* AllocatedType = MergableAlloca->alloca->getAllocatedType();
86+
auto* AllocatedTypeNew = NewAlloca->alloca->getAllocatedType();
87+
bool IsArray = AllocatedType->isArrayTy()? true : false;
88+
bool IsArrayNew = AllocatedTypeNew->isArrayTy()? true : false;
89+
bool AreBothArrays = IsArray && IsArrayNew;
90+
if (AreBothArrays && AllocatedType->getArrayElementType() != AllocatedTypeNew->getArrayElementType()) {
91+
return false;
92+
}
93+
if (!AreBothArrays && AllocatedType != AllocatedTypeNew) {
94+
return false;
95+
}
96+
}
97+
8398
// Check if we can merge alloca to one of existing non-overlapping allocas.
8499
for (auto *NonOverlappingAlloca : MergableAlloca->nonOverlapingAllocas) {
85100
bool added = AddNonOverlappingAlloca(NonOverlappingAlloca, NewAlloca);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
; SPDX-License-Identifier: MIT
66
;
77
;============================ end_copyright_notice =============================
8-
; RUN: igc_opt --igc-merge-allocas --igc-private-mem-resolution -S %s --platformpvc | FileCheck %s
8+
; REQUIRES: regkeys
9+
; RUN: igc_opt --regkey DisableMergingOfAllocasWithDifferentType=0 --igc-merge-allocas --igc-private-mem-resolution -S %s --platformpvc | FileCheck %s
910
; ------------------------------------------------
1011
; PrivateMemoryResolution
1112
; ------------------------------------------------

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;
77
;============================ end_copyright_notice =============================
88
; REQUIRES: regkeys
9-
; RUN: igc_opt --typed-pointers --regkey DisableMergingOfMultipleAllocasWithOffset=0 --igc-merge-allocas --igc-private-mem-resolution -S %s --platformpvc | FileCheck %s
9+
; RUN: igc_opt --typed-pointers --regkey DisableMergingOfMultipleAllocasWithOffset=0 --regkey DisableMergingOfAllocasWithDifferentType=0 --igc-merge-allocas --igc-private-mem-resolution -S %s --platformpvc | FileCheck %s
1010
; ------------------------------------------------
1111
; PrivateMemoryResolution
1212
; ------------------------------------------------

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
; SPDX-License-Identifier: MIT
66
;
77
;============================ end_copyright_notice =============================
8-
; RUN: igc_opt --typed-pointers --igc-merge-allocas --igc-private-mem-resolution -S %s --platformpvc | FileCheck %s
8+
; REQUIRES: regkeys
9+
; RUN: igc_opt --typed-pointers --regkey DisableMergingOfAllocasWithDifferentType=0 --igc-merge-allocas --igc-private-mem-resolution -S %s --platformpvc | FileCheck %s
910
; ------------------------------------------------
1011
; PrivateMemoryResolution
1112
; ------------------------------------------------

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
; SPDX-License-Identifier: MIT
66
;
77
;============================ end_copyright_notice =============================
8-
; RUN: igc_opt --typed-pointers --igc-merge-allocas --igc-private-mem-resolution -S %s --platformpvc | FileCheck %s
8+
; REQUIRES: regkeys
9+
; RUN: igc_opt --typed-pointers --regkey DisableMergingOfAllocasWithDifferentType=0 --igc-merge-allocas --igc-private-mem-resolution -S %s --platformpvc | FileCheck %s
910
; ------------------------------------------------
1011
; PrivateMemoryResolution
1112
; ------------------------------------------------

IGC/common/igc_flags.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,9 @@ DECLARE_IGC_GROUP("Raytracing Options")
992992
DECLARE_IGC_REGKEY(bool, DisablePrepareLoadsStores, false, "Disable preparation for MemOpt", true)
993993
DECLARE_IGC_REGKEY(bool, DisableRayTracingConstantCoalescing, false, "Disable coalescing", true)
994994
DECLARE_IGC_REGKEY(bool, DisableMergeAllocas, true, "Do not merge allocas prior to SplitAsyncPass", false)
995-
DECLARE_IGC_REGKEY(bool, DisableMergeAllocasPrivateMemory, false, "Do not merge allocas prior to PrivateMemoryResolution", false)
996-
DECLARE_IGC_REGKEY(bool, DisableMergingOfMultipleAllocasWithOffset, true, "Do not merge multiple smaller allocas under one larger one with different offsets.", false)
995+
DECLARE_IGC_REGKEY(bool, DisableMergeAllocasPrivateMemory, false, "Do not merge allocas prior to PrivateMemoryResolution", true)
996+
DECLARE_IGC_REGKEY(bool, DisableMergingOfMultipleAllocasWithOffset, true, "Do not merge multiple smaller allocas under one larger one with different offsets.", true)
997+
DECLARE_IGC_REGKEY(bool, DisableMergingOfAllocasWithDifferentType, true, "Do not merge allocas of different types.", true)
997998
DECLARE_IGC_REGKEY(DWORD, RayTracingConstantCoalescingMinBlockSize, 4, "Set the minimum load size in # OWords = [1,2,4,8,16].", true)
998999
DECLARE_IGC_REGKEY(bool, DisableRayTracingOptimizations, false, "Disable RayTracing Optimizations for debugging", true)
9991000
DECLARE_IGC_REGKEY(DWORD, RayTracingCustomTileXDim1D, 0, "X dimension of tile (default: DG2=256, Xe2+=512)", true)

0 commit comments

Comments
 (0)