Skip to content

Commit f1a5e72

Browse files
pkwasnie-inteligcbot
authored andcommitted
LSR pass: enable EnableGEPLSRMulExpr by default
Enables EnableGEPLSRMulExpr in GEP LSR pass. Fixes a bug where EnableGEPLSRUnknownConstantStep was always enabled together with MulExpr
1 parent a7dbd47 commit f1a5e72

12 files changed

+142
-61
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ class Analyzer
293293
bool doInitialValidation(GetElementPtrInst *GEP);
294294

295295
bool deconstructSCEV(const SCEV *S, const SCEV *&Start, const SCEV *&Step);
296+
bool isValidStep(const SCEV* S);
296297

297298
DominatorTree &DT;
298299
Loop &L;
@@ -966,7 +967,7 @@ void Analyzer::analyzeGEP(GetElementPtrInst *GEP)
966967
if (!deconstructSCEV(S, Start, Step))
967968
return;
968969

969-
if (Step->getSCEVType() != scConstant && IGC_IS_FLAG_DISABLED(EnableGEPLSRUnknownConstantStep) && IGC_IS_FLAG_DISABLED(EnableGEPLSRMulExpr))
970+
if (!isValidStep(Step))
970971
return;
971972

972973
if (S->getType() != Start->getType())
@@ -1193,6 +1194,20 @@ bool Analyzer::deconstructSCEV(const SCEV *S, const SCEV *&Start, const SCEV *&S
11931194
}
11941195

11951196

1197+
bool Analyzer::isValidStep(const SCEV* S)
1198+
{
1199+
auto Ty = SCEVHelper::dropExt(S)->getSCEVType();
1200+
1201+
if (Ty == scConstant)
1202+
return true;
1203+
1204+
if (Ty == scMulExpr && IGC_IS_FLAG_ENABLED(EnableGEPLSRMulExpr))
1205+
return true;
1206+
1207+
return IGC_IS_FLAG_ENABLED(EnableGEPLSRUnknownConstantStep);
1208+
}
1209+
1210+
11961211
RegisterPressureTracker::RegisterPressureTracker(Function &F, CodeGenContext &CGC, IGCLivenessAnalysis &RPE, IGCFunctionExternalRegPressureAnalysis &FRPE, WIAnalysisRunner &WI)
11971212
: RPE(RPE), WI(WI)
11981213
{

IGC/Compiler/tests/GEPLoopStrengthReduction/illegal_types-typed-pointers.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=EnableGEPLSRMulExpr=1 --regkey=EnableGEPLSRAnyIntBitWidth=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,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-prefixes=CHECK,CHECK-ALLOW-ILLEGAL
10+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=1 --regkey=EnableGEPLSRAnyIntBitWidth=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-BLOCK-ILLEGAL
11+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=1 --regkey=EnableGEPLSRAnyIntBitWidth=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-ALLOW-ILLEGAL
1212
;
1313
; Test for illegal types in SCEV expressions.
1414

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: opaque-ptr-fix, llvm-14-plus, regkeys
10-
; RUN: igc_opt --opaque-pointers --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 --opaque-pointers --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
10+
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRUnknownConstantStep=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 --opaque-pointers --regkey=EnableGEPLSRUnknownConstantStep=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-typed-pointers.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;============================ end_copyright_notice =============================
88

99
; REQUIRES: regkeys
10-
; RUN: igc_opt --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
10+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=0 --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
1111

1212
; Reduced index is expressed with SCEVMulExpr.
1313

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_mulexpr_decrement.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;============================ end_copyright_notice =============================
88

99
; REQUIRES: opaque-ptr-fix, llvm-14-plus, regkeys
10-
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
10+
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRUnknownConstantStep=0 --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
1111

1212
; Reduced index is expressed with SCEVMulExpr.
1313

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_mulexpr_increment-typed-pointers.ll

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

99
; REQUIRES: regkeys
10-
; RUN: igc_opt --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
10+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=0 --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-MUL-ENABLED
11+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=0 --regkey=EnableGEPLSRMulExpr=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-MUL-DISABLED
1112

1213
; Reduced index is expressed with SCEVMulExpr.
1314

@@ -20,21 +21,36 @@ entry:
2021
br i1 %cmp1, label %for.body.lr.ph, label %for.end
2122

2223
; CHECK-LABEL: for.body.lr.ph:
23-
; CHECK: [[MULL:%.*]] = mul i64 %multiplier, 44
24-
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[MULL]]
25-
; CHECK: [[STEP:%.*]] = shl i64 %multiplier, 1
26-
; CHECK: br label %for.body
24+
;
25+
; CHECK-MUL-ENABLED: [[MULL:%.*]] = mul i64 %multiplier, 44
26+
; CHECK-MUL-ENABLED: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[MULL]]
27+
; CHECK-MUL-ENABLED: [[STEP:%.*]] = shl i64 %multiplier, 1
28+
;
29+
; CHECK-MUL-DISABLED-NOT: gep
30+
;
31+
; CHECK: br label %for.body
2732
for.body.lr.ph: ; preds = %entry
2833
br label %for.body
2934

3035
; CHECK-LABEL: for.body:
31-
; CHECK: [[GEP:%.*]] = phi i32 addrspace(1)* [ [[GEP_PHI1]], %for.body.lr.ph ], [ [[GEP_PHI2:%.*]], %for.body ]
32-
; CHECK: %i.02 = phi i32 [ 39, %for.body.lr.ph ], [ %inc, %for.body ]
33-
; CHECK: store i32 11, i32 addrspace(1)* [[GEP]], align 4
34-
; CHECK: %inc = add nuw nsw i32 %i.02, 2
35-
; CHECK: %cmp = icmp slt i32 %inc, %n
36-
; CHECK: [[GEP_PHI2]] = getelementptr i32, i32 addrspace(1)* [[GEP]], i64 [[STEP]]
37-
; CHECK: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
36+
;
37+
; CHECK-MUL-ENABLED: [[GEP:%.*]] = phi i32 addrspace(1)* [ [[GEP_PHI1]], %for.body.lr.ph ], [ [[GEP_PHI2:%.*]], %for.body ]
38+
; CHECK-MUL-ENABLED: %i.02 = phi i32 [ 39, %for.body.lr.ph ], [ %inc, %for.body ]
39+
; CHECK-MUL-ENABLED: store i32 11, i32 addrspace(1)* [[GEP]], align 4
40+
; CHECK-MUL-ENABLED: %inc = add nuw nsw i32 %i.02, 2
41+
; CHECK-MUL-ENABLED: %cmp = icmp slt i32 %inc, %n
42+
; CHECK-MUL-ENABLED: [[GEP_PHI2]] = getelementptr i32, i32 addrspace(1)* [[GEP]], i64 [[STEP]]
43+
; CHECK-MUL-ENABLED: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
44+
;
45+
; CHECK-MUL-DISABLED: %i.02 = phi i32 [ 39, %for.body.lr.ph ], [ %inc, %for.body ]
46+
; CHECK-MUL-DISABLED: %add = add nsw i32 %i.02, 5
47+
; CHECK-MUL-DISABLED: %zext = zext i32 %add to i64
48+
; CHECK-MUL-DISABLED: %idxprom = mul i64 %zext, %multiplier
49+
; CHECK-MUL-DISABLED: %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 %idxprom
50+
; CHECK-MUL-DISABLED: store i32 11, i32 addrspace(1)* %arrayidx, align 4
51+
; CHECK-MUL-DISABLED: %inc = add nuw nsw i32 %i.02, 2
52+
; CHECK-MUL-DISABLED: %cmp = icmp slt i32 %inc, %n
53+
; CHECK-MUL-DISABLED: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
3854
for.body: ; preds = %for.body.lr.ph, %for.body
3955
%i.02 = phi i32 [ 39, %for.body.lr.ph ], [ %inc, %for.body ]
4056
%add = add nsw i32 %i.02, 5

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_mulexpr_increment.ll

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

99
; REQUIRES: opaque-ptr-fix, llvm-14-plus, regkeys
10-
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
10+
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRUnknownConstantStep=0 --regkey=EnableGEPLSRMulExpr=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-MUL-ENABLED
11+
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRUnknownConstantStep=0 --regkey=EnableGEPLSRMulExpr=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-MUL-DISABLED
1112

1213
; Reduced index is expressed with SCEVMulExpr.
1314

@@ -20,21 +21,36 @@ entry:
2021
br i1 %cmp1, label %for.body.lr.ph, label %for.end
2122

2223
; CHECK-LABEL: for.body.lr.ph:
23-
; CHECK: [[MULL:%.*]] = mul i64 %multiplier, 44
24-
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[MULL]]
25-
; CHECK: [[STEP:%.*]] = shl i64 %multiplier, 1
26-
; CHECK: br label %for.body
24+
;
25+
; CHECK-MUL-ENABLED: [[MULL:%.*]] = mul i64 %multiplier, 44
26+
; CHECK-MUL-ENABLED: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[MULL]]
27+
; CHECK-MUL-ENABLED: [[STEP:%.*]] = shl i64 %multiplier, 1
28+
;
29+
; CHECK-MUL-DISABLED-NOT: gep
30+
;
31+
; CHECK: br label %for.body
2732
for.body.lr.ph: ; preds = %entry
2833
br label %for.body
2934

3035
; CHECK-LABEL: for.body:
31-
; CHECK: [[GEP:%.*]] = phi i32 addrspace(1)* [ [[GEP_PHI1]], %for.body.lr.ph ], [ [[GEP_PHI2:%.*]], %for.body ]
32-
; CHECK: %i.02 = phi i32 [ 39, %for.body.lr.ph ], [ %inc, %for.body ]
33-
; CHECK: store i32 11, i32 addrspace(1)* [[GEP]], align 4
34-
; CHECK: %inc = add nuw nsw i32 %i.02, 2
35-
; CHECK: %cmp = icmp slt i32 %inc, %n
36-
; CHECK: [[GEP_PHI2]] = getelementptr i32, i32 addrspace(1)* [[GEP]], i64 [[STEP]]
37-
; CHECK: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
36+
;
37+
; CHECK-MUL-ENABLED: [[GEP:%.*]] = phi i32 addrspace(1)* [ [[GEP_PHI1]], %for.body.lr.ph ], [ [[GEP_PHI2:%.*]], %for.body ]
38+
; CHECK-MUL-ENABLED: %i.02 = phi i32 [ 39, %for.body.lr.ph ], [ %inc, %for.body ]
39+
; CHECK-MUL-ENABLED: store i32 11, i32 addrspace(1)* [[GEP]], align 4
40+
; CHECK-MUL-ENABLED: %inc = add nuw nsw i32 %i.02, 2
41+
; CHECK-MUL-ENABLED: %cmp = icmp slt i32 %inc, %n
42+
; CHECK-MUL-ENABLED: [[GEP_PHI2]] = getelementptr i32, i32 addrspace(1)* [[GEP]], i64 [[STEP]]
43+
; CHECK-MUL-ENABLED: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
44+
;
45+
; CHECK-MUL-DISABLED: %i.02 = phi i32 [ 39, %for.body.lr.ph ], [ %inc, %for.body ]
46+
; CHECK-MUL-DISABLED: %add = add nsw i32 %i.02, 5
47+
; CHECK-MUL-DISABLED: %zext = zext i32 %add to i64
48+
; CHECK-MUL-DISABLED: %idxprom = mul i64 %zext, %multiplier
49+
; CHECK-MUL-DISABLED: %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 %idxprom
50+
; CHECK-MUL-DISABLED: store i32 11, i32 addrspace(1)* %arrayidx, align 4
51+
; CHECK-MUL-DISABLED: %inc = add nuw nsw i32 %i.02, 2
52+
; CHECK-MUL-DISABLED: %cmp = icmp slt i32 %inc, %n
53+
; CHECK-MUL-DISABLED: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
3854
for.body: ; preds = %for.body.lr.ph, %for.body
3955
%i.02 = phi i32 [ 39, %for.body.lr.ph ], [ %inc, %for.body ]
4056
%add = add nsw i32 %i.02, 5

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_unknown_constant_step-typed-pointers.ll

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

99
; REQUIRES: regkeys
10-
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
10+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=1 --regkey=EnableGEPLSRMulExpr=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-UNKNOWN-ENABLED
11+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=0 --regkey=EnableGEPLSRMulExpr=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-UNKNOWN-DISABLED
1112

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

@@ -20,22 +21,38 @@ entry:
2021
br i1 %cmp1, label %for.body.lr.ph, label %for.end
2122

2223
; CHECK-LABEL: for.body.lr.ph:
23-
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 0
24-
; CHECK: br label %for.body
24+
;
25+
; CHECK-UNKNOWN-ENABLED: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 0
26+
;
27+
; CHECK-UNKNOWN-DISABLED-NOT: gep
28+
;
29+
; CHECK: br label %for.body
2530
for.body.lr.ph: ; preds = %entry
2631
br label %for.body
2732

2833
; CHECK-LABEL: for.body:
29-
; CHECK: [[GEP:%.*]] = phi i32 addrspace(1)* [ [[GEP_PHI1]], %for.body.lr.ph ], [ [[GEP_PHI2:%.*]], %for.body ]
30-
; CHECK: %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
31-
; CHECK-NOT: getelementptr inbounds i32, i32 addrspace(1)* %p
32-
; CHECK: [[LOAD:%.*]] = load i32, i32 addrspace(1)* [[GEP]], align 4
33-
; CHECK: %add = add nsw i32 [[LOAD]], 1
34-
; CHECK: store i32 %add, i32 addrspace(1)* [[GEP]], align 4
35-
; CHECK: %inc = add nuw nsw i32 %i.02, 1
36-
; CHECK: %cmp = icmp slt i32 %inc, %n
37-
; CHECK: [[GEP_PHI2]] = getelementptr i32, i32 addrspace(1)* [[GEP]], i64 %step
38-
; CHECK: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
34+
;
35+
; CHECK-UNKNOWN-ENABLED: [[GEP:%.*]] = phi i32 addrspace(1)* [ [[GEP_PHI1]], %for.body.lr.ph ], [ [[GEP_PHI2:%.*]], %for.body ]
36+
; CHECK-UNKNOWN-ENABLED: %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
37+
; CHECK-UNKNOWN-ENABLED-NOT: getelementptr inbounds i32, i32 addrspace(1)* %p
38+
; CHECK-UNKNOWN-ENABLED: [[LOAD:%.*]] = load i32, i32 addrspace(1)* [[GEP]], align 4
39+
; CHECK-UNKNOWN-ENABLED: %add = add nsw i32 [[LOAD]], 1
40+
; CHECK-UNKNOWN-ENABLED: store i32 %add, i32 addrspace(1)* [[GEP]], align 4
41+
; CHECK-UNKNOWN-ENABLED: %inc = add nuw nsw i32 %i.02, 1
42+
; CHECK-UNKNOWN-ENABLED: %cmp = icmp slt i32 %inc, %n
43+
; CHECK-UNKNOWN-ENABLED: [[GEP_PHI2]] = getelementptr i32, i32 addrspace(1)* [[GEP]], i64 %step
44+
; CHECK-UNKNOWN-ENABLED: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
45+
;
46+
; CHECK-UNKNOWN-DISABLED: %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
47+
; CHECK-UNKNOWN-DISABLED: %idxprom = zext i32 %i.02 to i64
48+
; CHECK-UNKNOWN-DISABLED: %idxprom2 = mul i64 %idxprom, %step
49+
; CHECK-UNKNOWN-DISABLED: %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 %idxprom2
50+
; CHECK-UNKNOWN-DISABLED: %0 = load i32, i32 addrspace(1)* %arrayidx, align 4
51+
; CHECK-UNKNOWN-DISABLED: %add = add nsw i32 %0, 1
52+
; CHECK-UNKNOWN-DISABLED: store i32 %add, i32 addrspace(1)* %arrayidx, align 4
53+
; CHECK-UNKNOWN-DISABLED: %inc = add nuw nsw i32 %i.02, 1
54+
; CHECK-UNKNOWN-DISABLED: %cmp = icmp slt i32 %inc, %n
55+
; CHECK-UNKNOWN-DISABLED: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
3956
for.body: ; preds = %for.body.lr.ph, %for.body
4057
%i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
4158
%idxprom = zext i32 %i.02 to i64

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_unknown_constant_step.ll

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

99
; REQUIRES: opaque-ptr-fix, llvm-14-plus, regkeys
10-
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRUnknownConstantStep=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
10+
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRUnknownConstantStep=1 --regkey=EnableGEPLSRMulExpr=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-UNKNOWN-ENABLED
11+
; RUN: igc_opt --opaque-pointers --regkey=EnableGEPLSRUnknownConstantStep=0 --regkey=EnableGEPLSRMulExpr=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-UNKNOWN-DISABLED
1112

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

@@ -20,22 +21,38 @@ entry:
2021
br i1 %cmp1, label %for.body.lr.ph, label %for.end
2122

2223
; CHECK-LABEL: for.body.lr.ph:
23-
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 0
24-
; CHECK: br label %for.body
24+
;
25+
; CHECK-UNKNOWN-ENABLED: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 0
26+
;
27+
; CHECK-UNKNOWN-DISABLED-NOT: gep
28+
;
29+
; CHECK: br label %for.body
2530
for.body.lr.ph: ; preds = %entry
2631
br label %for.body
2732

2833
; CHECK-LABEL: for.body:
29-
; CHECK: [[GEP:%.*]] = phi i32 addrspace(1)* [ [[GEP_PHI1]], %for.body.lr.ph ], [ [[GEP_PHI2:%.*]], %for.body ]
30-
; CHECK: %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
31-
; CHECK-NOT: getelementptr inbounds i32, i32 addrspace(1)* %p
32-
; CHECK: [[LOAD:%.*]] = load i32, i32 addrspace(1)* [[GEP]], align 4
33-
; CHECK: %add = add nsw i32 [[LOAD]], 1
34-
; CHECK: store i32 %add, i32 addrspace(1)* [[GEP]], align 4
35-
; CHECK: %inc = add nuw nsw i32 %i.02, 1
36-
; CHECK: %cmp = icmp slt i32 %inc, %n
37-
; CHECK: [[GEP_PHI2]] = getelementptr i32, i32 addrspace(1)* [[GEP]], i64 %step
38-
; CHECK: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
34+
;
35+
; CHECK-UNKNOWN-ENABLED: [[GEP:%.*]] = phi i32 addrspace(1)* [ [[GEP_PHI1]], %for.body.lr.ph ], [ [[GEP_PHI2:%.*]], %for.body ]
36+
; CHECK-UNKNOWN-ENABLED: %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
37+
; CHECK-UNKNOWN-ENABLED-NOT: getelementptr inbounds i32, i32 addrspace(1)* %p
38+
; CHECK-UNKNOWN-ENABLED: [[LOAD:%.*]] = load i32, i32 addrspace(1)* [[GEP]], align 4
39+
; CHECK-UNKNOWN-ENABLED: %add = add nsw i32 [[LOAD]], 1
40+
; CHECK-UNKNOWN-ENABLED: store i32 %add, i32 addrspace(1)* [[GEP]], align 4
41+
; CHECK-UNKNOWN-ENABLED: %inc = add nuw nsw i32 %i.02, 1
42+
; CHECK-UNKNOWN-ENABLED: %cmp = icmp slt i32 %inc, %n
43+
; CHECK-UNKNOWN-ENABLED: [[GEP_PHI2]] = getelementptr i32, i32 addrspace(1)* [[GEP]], i64 %step
44+
; CHECK-UNKNOWN-ENABLED: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
45+
;
46+
; CHECK-UNKNOWN-DISABLED: %i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
47+
; CHECK-UNKNOWN-DISABLED: %idxprom = zext i32 %i.02 to i64
48+
; CHECK-UNKNOWN-DISABLED: %idxprom2 = mul i64 %idxprom, %step
49+
; CHECK-UNKNOWN-DISABLED: %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 %idxprom2
50+
; CHECK-UNKNOWN-DISABLED: %0 = load i32, i32 addrspace(1)* %arrayidx, align 4
51+
; CHECK-UNKNOWN-DISABLED: %add = add nsw i32 %0, 1
52+
; CHECK-UNKNOWN-DISABLED: store i32 %add, i32 addrspace(1)* %arrayidx, align 4
53+
; CHECK-UNKNOWN-DISABLED: %inc = add nuw nsw i32 %i.02, 1
54+
; CHECK-UNKNOWN-DISABLED: %cmp = icmp slt i32 %inc, %n
55+
; CHECK-UNKNOWN-DISABLED: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
3956
for.body: ; preds = %for.body.lr.ph, %for.body
4057
%i.02 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
4158
%idxprom = zext i32 %i.02 to i64

IGC/Compiler/tests/GEPLoopStrengthReduction/two_accesses_unknown_constant_step-typed-pointers.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;============================ end_copyright_notice =============================
88

99
; REQUIRES: regkeys
10-
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=1 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
10+
; RUN: igc_opt --regkey=EnableGEPLSRUnknownConstantStep=1 --regkey=EnableGEPLSRMulExpr=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
1111

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

0 commit comments

Comments
 (0)