Skip to content

Commit a3359df

Browse files
esukhovigcbot
authored andcommitted
Enable Clone Address Arithmetic pass on retry & RPE cutoff
Original pass: 131312e Clone address arithmetic pass is enabled on retry. RPE is used as a cutoff to prevent unnecessary rematerialization on kernels that no longer have spills.
1 parent 078fc68 commit a3359df

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

IGC/Compiler/CISACodeGen/IGCLivenessAnalysis.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ IGC_INITIALIZE_PASS_END(IGCLivenessAnalysis, PASS_FLAG2, PASS_DESCRIPTION2,
3838
PASS_CFG_ONLY2, PASS_ANALYSIS2)
3939
#define PRINT(str) llvm::errs() << str
4040

41+
42+
IGCLivenessAnalysis::IGCLivenessAnalysis() : FunctionPass(ID) { UseWIAnalysis = true; };
43+
4144
IGCLivenessAnalysis::IGCLivenessAnalysis(bool UseWiAnalysisVar /* = false */,
4245
bool DumpToFileVar /* = false */,
4346
const std::string &DumpFileNameVar)

IGC/Compiler/CISACodeGen/IGCLivenessAnalysis.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ class IGCLivenessAnalysis : public llvm::FunctionPass {
5555
llvm::StringRef getPassName() const override {
5656
return "IGCLivenessAnalysis";
5757
}
58+
59+
IGCLivenessAnalysis();
5860
IGCLivenessAnalysis(
59-
bool UseWIAnalysis = false, bool DumpToFile = false,
60-
const std::string &DumpFileName = "RegPressureEstimate.ll");
61+
bool UseWIAnalysis, bool DumpToFile,
62+
const std::string &DumpFileName);
6163

6264
virtual ~IGCLivenessAnalysis() {}
6365

IGC/Compiler/CISACodeGen/RematAddressArithmetic.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SPDX-License-Identifier: MIT
1414
#include "llvm/Analysis/PostDominators.h"
1515
#include "llvm/ADT/BreadthFirstIterator.h"
1616
#include "common/LLVMWarningsPop.hpp"
17+
#include "Compiler/CISACodeGen/IGCLivenessAnalysis.h"
1718

1819
using namespace llvm;
1920
using namespace IGC;
@@ -60,6 +61,7 @@ class CloneAddressArithmetic : public FunctionPass {
6061

6162
virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override {
6263
AU.setPreservesCFG();
64+
AU.addRequired<IGCLivenessAnalysis>();
6365
}
6466

6567
bool runOnFunction(Function&) override;
@@ -88,6 +90,7 @@ char CloneAddressArithmetic::ID = 0;
8890
#define PASS_ANALYSIS_2 false
8991
namespace IGC {
9092
IGC_INITIALIZE_PASS_BEGIN(CloneAddressArithmetic, PASS_FLAG_2, PASS_DESC_2, PASS_CFG_ONLY_2, PASS_ANALYSIS_2)
93+
IGC_INITIALIZE_PASS_DEPENDENCY(IGCLivenessAnalysis)
9194
IGC_INITIALIZE_PASS_END(CloneAddressArithmetic, PASS_FLAG_2, PASS_DESC_2, PASS_CFG_ONLY_2, PASS_ANALYSIS_2)
9295
}
9396

@@ -184,6 +187,12 @@ bool CloneAddressArithmetic::greedyRemat(Function &F) {
184187

185188
bool Result = false;
186189

190+
auto RPE = &getAnalysis<IGCLivenessAnalysis>();
191+
unsigned int SIMD = numLanes(RPE->bestGuessSIMDSize());
192+
unsigned int PressureLimit = IGC_GET_FLAG_VALUE(RematRPELimit);
193+
if(RPE->getMaxRegCountForFunction(F, SIMD) < PressureLimit)
194+
return Result;
195+
187196
for (BasicBlock &BB : F) {
188197
for (auto &I : BB) { Uses[&I] = I.getNumUses(); }
189198
}

IGC/Compiler/CISACodeGen/ShaderCodeGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,8 @@ void AddLegalizationPasses(CodeGenContext& ctx, IGCPassManager& mpm, PSSignature
893893
// Run address remat after GVN as it may hoist address calculations and
894894
// create PHI nodes with addresses.
895895

896-
if (IGC_IS_FLAG_ENABLED(EnableRemat)) {
896+
if (IGC_IS_FLAG_ENABLED(EnableRemat) || (ctx.m_retryManager.AllowCloneAddressArithmetic() && ctx.type == ShaderType::OPENCL_SHADER)) {
897+
897898

898899
// TODO: This is a workaround that helps to reduce amount of instructions for clone address arithmetic
899900
// it helps with chain of instructions like this

IGC/Compiler/tests/RematAddressArithmetic/cloneAddressArithmetic.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
;
77
;============================ end_copyright_notice =============================
88

9-
; RUN: igc_opt %s -S -o - -igc-clone-address-arithmetic --regkey=RematChainLimit=10 --dce | FileCheck %s
9+
; UNSUPPORTED: system-windows
10+
; RUN: igc_opt %s -S -o - -igc-clone-address-arithmetic --regkey=RematChainLimit=10 --regkey=RematRPELimit=0 --dce | FileCheck %s
1011

1112
define spir_kernel void @main(double addrspace(1)* %base, i64 %offset, i64 %I, i64 %J) {
1213
; CHECK: define spir_kernel void @main(double addrspace(1)* [[BASE:%.*]], i64 [[OFFSET:%.*]], i64 %I, i64 %J)

IGC/common/igc_flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ DECLARE_IGC_REGKEY(DWORD, MemOptWindowSize, 150, "Size of the window in unit
736736
DECLARE_IGC_REGKEY(DWORD, RematBlockSize, 10, "Represents a threshold for a basic block size which determines whether this block will be processed for rematerialization or not", false)
737737
DECLARE_IGC_REGKEY(DWORD, RematUsesThreshold, 5, "Amount of uses after which operand is not rematerialized", false)
738738
DECLARE_IGC_REGKEY(DWORD, RematChainLimit, 10, "If number of instructions we've collected is more than this value, we bail on it", false)
739+
DECLARE_IGC_REGKEY(DWORD, RematRPELimit, 100, "Cutoff value for register estimator, lower than that, kernel won't be rematted", false)
739740
DECLARE_IGC_REGKEY(bool, RematSameBBScope, true, "Confine rematerialization only to variables within the same BB, we won't pull down values from predeccors", false)
740741
DECLARE_IGC_REGKEY(bool, EnableRemat, false, "Enable clone adress arithmetic pass not only on retry", false)
741742
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)

0 commit comments

Comments
 (0)