Skip to content

Commit 75c4209

Browse files
stefan-iligcbot
authored andcommitted
Apply remat to function arguments
Try to reduce impact of MergeAllocas on register pressure.
1 parent cc11ec5 commit 75c4209

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

IGC/Compiler/CISACodeGen/RematAddressArithmetic.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,23 @@ void CloneAddressArithmetic::collectInstToProcess(RematSet& ToProcess, Function&
527527

528528
bool IsLoad = llvm::isa<LoadInst>(I);
529529
bool IsStore = llvm::isa<StoreInst>(I);
530-
if (!IsLoad && !IsStore) continue;
530+
bool IsCall = llvm::isa<CallInst>(I);
531+
if (!IsLoad && !IsStore && !IsCall) continue;
531532

532533
llvm::Value* V =
533534
IsLoad ? static_cast<LoadInst *>(&I)->getPointerOperand() :
534535
static_cast<StoreInst *>(&I)->getPointerOperand();
535536

536537
if(isRematInstruction(V))
537538
ToProcess.insert(static_cast<Instruction *>(V));
539+
540+
if (IsCall && IGC_IS_FLAG_ENABLED(RematCollectCallArgs)) {
541+
for (auto &Arg : cast<CallInst>(I).args()) {
542+
if(isRematInstruction(Arg)) {
543+
ToProcess.insert(cast<Instruction>(&Arg));
544+
}
545+
}
546+
}
538547
}
539548
}
540549
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; REQUIRES: regkeys
10+
; UNSUPPORTED: system-windows
11+
; RUN: igc_opt --typed-pointers %s -S -o - -igc-clone-address-arithmetic --regkey=RematChainLimit=10 --regkey=RematFlowThreshold=100 --regkey=RematRPELimit=0 --dce | FileCheck %s
12+
13+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
14+
target triple = "spir64-unknown-unknown"
15+
16+
%"struct.ONEAPIKernelContext::LightSample" = type { %struct.packed_float3, %struct.packed_float3, %struct.packed_float3, float, float, float, float, float, float, i32, i32, i32, i32, i32, i32 }
17+
%struct.packed_float3 = type { float, float, float }
18+
19+
declare spir_func void @target_func(%"struct.ONEAPIKernelContext::LightSample" addrspace(4)*)
20+
21+
define spir_kernel void @main() {
22+
entry:
23+
%ls.i = alloca %"struct.ONEAPIKernelContext::LightSample", i32 0, align 4
24+
br label %if.end46
25+
26+
if.end46:
27+
%ls.ascast.i = addrspacecast %"struct.ONEAPIKernelContext::LightSample"* %ls.i to %"struct.ONEAPIKernelContext::LightSample" addrspace(4)*
28+
br label %cleanup.cont.i
29+
; CHECK-LABEL: cleanup.cont.i:
30+
; CHECK-NEXT: [[REMAT:%.*]] = alloca %"struct.ONEAPIKernelContext::LightSample", i32 0, align 4
31+
; CHECK-NEXT: [[CAST:%.*]] = addrspacecast %"struct.ONEAPIKernelContext::LightSample"* [[REMAT]] to %"struct.ONEAPIKernelContext::LightSample" addrspace(4)*
32+
; CHECK-NEXT: call spir_func void @target_func(%"struct.ONEAPIKernelContext::LightSample" addrspace(4)* [[CAST]])
33+
cleanup.cont.i: ; preds = %if.end46
34+
call spir_func void @target_func(%"struct.ONEAPIKernelContext::LightSample" addrspace(4)* %ls.ascast.i)
35+
ret void
36+
}

IGC/common/igc_flags.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,8 @@ DECLARE_IGC_REGKEY(bool, RematAllowExtractElement, false, "Allow Extract Element
861861
DECLARE_IGC_REGKEY(bool, RematReassocBefore, false, "Enable short sequence of passes before clone address arithmetic pass to potentially decrese amount of operations that will be rematerialized", false)
862862
DECLARE_IGC_REGKEY(bool, RematInstCombineBefore, false, "Enable short sequence of passes before clone address arithmetic pass to potentially decrese amount of operations that will be rematerialized", false)
863863
DECLARE_IGC_REGKEY(bool, RematAddrSpaceCastToUse, true, "Allow rematerialization of inttoptr that are used inside AddrSpaceCastInst", false)
864-
DECLARE_IGC_REGKEY(bool, RematCallsOperand, false, "Allow rematerialization of inttoptr that are used as call's operand", false)
864+
DECLARE_IGC_REGKEY(bool, RematCallsOperand, true, "Allow rematerialization of inttoptr that are used as call's operand", false)
865+
DECLARE_IGC_REGKEY(bool, RematCollectCallArgs, true, "Allow collection of call arguments for rematerialization", false)
865866
DECLARE_IGC_REGKEY(bool, RematAllowOneUseLoad, false, "Remat allow to move loads that have one use and it's inside the chain", false)
866867
DECLARE_IGC_REGKEY(bool, RematAllowLoads, false, "Remat allow to move loads, no checks, exclusively for testing purposes", false)
867868
DECLARE_IGC_REGKEY(bool, DumpRegPressureEstimate, false, "Dump RegPressureEstimate to a file", false)

0 commit comments

Comments
 (0)