Skip to content

Commit 850d0a1

Browse files
pkwasnie-inteligcbot
authored andcommitted
GEP Loop Strength Reduction pass - add optional IGC flags to
enable mul expressions and non-constant int steps Adds new flags: 1. EnableGEPLSRUnknownConstantStep - If enabled, allows expressions with steps unknown at compilation time. Disabled by default. 2. EnableGEPLSRMulExpr - If enabled, allows expressions with mul. Disabled by default. If enabled, also enables EnableGEPLSRUnknownConstantStep.
1 parent 76c17a2 commit 850d0a1

File tree

7 files changed

+18
-6
lines changed

7 files changed

+18
-6
lines changed

IGC/Compiler/Optimizer/OpenCLPasses/GEPLoopStrengthReduction/GEPLoopStrengthReduction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,9 @@ void Analyzer::analyzeGEP(GetElementPtrInst *GEP)
937937
if (!deconstructSCEV(S, Start, Step))
938938
return;
939939

940+
if (Step->getSCEVType() != scConstant && IGC_IS_FLAG_DISABLED(EnableGEPLSRUnknownConstantStep) && IGC_IS_FLAG_DISABLED(EnableGEPLSRMulExpr))
941+
return;
942+
940943
if (S->getType() != Start->getType())
941944
Start = isa<SCEVSignExtendExpr>(S) ? SE.getSignExtendExpr(Start, S->getType()) : SE.getZeroExtendExpr(Start, S->getType());
942945

@@ -1115,6 +1118,9 @@ bool Analyzer::deconstructSCEV(const SCEV *S, const SCEV *&Start, const SCEV *&S
11151118
// Warning: GEP's new index will not be a constant integer, but a new SCEV expression.
11161119
if (auto *Mul = dyn_cast<SCEVMulExpr>(S))
11171120
{
1121+
if (IGC_IS_FLAG_DISABLED(EnableGEPLSRMulExpr))
1122+
return false;
1123+
11181124
// SCEVAddRecExpr will be SCEV with step != 0. Any other SCEV is a multiplier.
11191125
bool FoundAddRec = false;
11201126
SCEVHelper::SCEVMulBuilder StartBuilder(SE), StepBuilder(SE);

IGC/Compiler/tests/GEPLoopStrengthReduction/illegal_types.ll

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

99
; REQUIRES: regkeys
10-
; RUN: igc_opt --regkey=EnableGEPLSRAnyIntBitWidth=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK-BLOCK-ILLEGAL
11-
; RUN: igc_opt --regkey=EnableGEPLSRAnyIntBitWidth=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK-ALLOW-ILLEGAL
10+
; RUN: igc_opt --regkey=EnableGEPLSRMulExpr=1 --regkey=EnableGEPLSRAnyIntBitWidth=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK-BLOCK-ILLEGAL
11+
; RUN: igc_opt --regkey=EnableGEPLSRMulExpr=1 --regkey=EnableGEPLSRAnyIntBitWidth=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK-ALLOW-ILLEGAL
1212
;
1313
; Test for illegal types in SCEV expressions.
1414

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_mulexpr_decrement.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 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
9+
; REQUIRES: regkeys
10+
; RUN: igc_opt --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
1011

1112
; Reduced index is expressed with SCEVMulExpr.
1213

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_mulexpr_increment.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 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
9+
; REQUIRES: regkeys
10+
; RUN: igc_opt --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
1011

1112
; Reduced index is expressed with SCEVMulExpr.
1213

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_unknown_constant_step.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 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
9+
; REQUIRES: regkeys
10+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
1011

1112
; Pointer is indexed with an uknown value. As long as the step is constant, we can optimize GEP.
1213

IGC/Compiler/tests/GEPLoopStrengthReduction/two_accesses_unknown_constant_step.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 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
9+
; REQUIRES: regkeys
10+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
1011

1112
; Pointer is indexed with an uknown value. As long as the step is constant, we can optimize GEP.
1213

IGC/common/igc_flags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ DECLARE_IGC_REGKEY(bool, RunGEPLSRAfterLICM, false, "Runs GEP Loop Strength Redu
293293
DECLARE_IGC_REGKEY(DWORD, GEPLSRThresholdRatio, 100, "Ratio for register pressure threshold in GEP Loop Strength Reduction pass", true)
294294
DECLARE_IGC_REGKEY(bool, EnableGEPLSRToPreheader, true, "Enables reduction to loop's preheader in GEP Loop Strength Reduction pass", true)
295295
DECLARE_IGC_REGKEY(bool, EnableGEPLSRAnyIntBitWidth, false, "Experimental: Enables reduction of SCEV with illegal integers. Requires legalization pass to clear up expanded code.", true)
296+
DECLARE_IGC_REGKEY(bool, EnableGEPLSRMulExpr, false, "Experimental: Enables reduction of SCEV with mul expression.", true)
297+
DECLARE_IGC_REGKEY(bool, EnableGEPLSRUnknownConstantStep, false, "Experimental: Enables reduction of SCEV with step expressed with constant value unknown at compilation time.", true)
296298
DECLARE_IGC_REGKEY(DWORD, FPRoundingModeCoalescingMaxDistance, 20, "Max distance in instructions for reordering FP instructions with common rounding mode", false)
297299
DECLARE_IGC_REGKEY(bool, DisableDotAddToDp4aMerge, false, "Disable Dot and Add ops to Dp4a merge optimization.", false)
298300
DECLARE_IGC_REGKEY(bool, DisableLoopSplitWidePHIs, false, "Disable splitting of loop PHI values to eliminate subvector extract operations", false)

0 commit comments

Comments
 (0)