Skip to content

Commit 0c02929

Browse files
pkwasnie-intelpszymich
authored andcommitted
GEP Loop Strength Reduction pass - don't truncate index type
Don't truncate index type when inserting new GEP instructions. (cherry picked from commit 3afd57f)
1 parent 46bd9a4 commit 0c02929

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,9 @@ void Analyzer::analyzeGEP(GetElementPtrInst *GEP)
816816
if (!deconstructSCEV(S, Start, Step))
817817
return;
818818

819+
if (S->getType() != Start->getType())
820+
Start = SE.getZeroExtendExpr(Start, S->getType());
821+
819822
// Try adding reduction to existing group
820823
for (auto &c : Candidates)
821824
{
@@ -908,6 +911,7 @@ bool Analyzer::doInitialValidation(GetElementPtrInst *GEP)
908911
// parsed and reduced.
909912
bool Analyzer::deconstructSCEV(const SCEV *S, const SCEV *&Start, int64_t &Step)
910913
{
914+
// Drop ext instructions to analyze nested content.
911915
S = SCEVHelper::dropExt(S);
912916

913917
// First check if expression can be fully expanded in preheader. If so, no need

IGC/Compiler/tests/GEPLoopStrengthReduction/heuristic_instruction_count.ll

Lines changed: 3 additions & 4 deletions
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=GEPLSRNewInstructionThreshold=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,%LLVM_DEPENDENT_CHECK_PREFIX%
10+
; RUN: igc_opt --regkey=GEPLSRNewInstructionThreshold=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
1111
;
1212
; Input:
1313
;
@@ -51,7 +51,7 @@ for.cond1.preheader.lr.ph: ; preds = %entry
5151
; CHECK-LABEL: for.cond1.preheader:
5252
; CHECK: %j.07 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %inc27, %for.inc26 ]
5353
; CHECK: [[MUL:%.*]] = mul i32 %j.07, 10
54-
; CHECK-LLVM-14-PLUS: [[ZEXT:%.*]] = zext i32 [[MUL]] to i64
54+
; CHECK: [[ZEXT:%.*]] = zext i32 [[MUL]] to i64
5555
; CHECK: br i1 true, label %for.body4.lr.ph, label %for.cond7.preheader
5656
for.cond1.preheader: ; preds = %for.cond1.preheader.lr.ph, %for.inc26
5757
%j.07 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %inc27, %for.inc26 ]
@@ -70,8 +70,7 @@ for.cond7.preheader: ; preds = %for.cond1.for.cond7
7070
; Loop k2 receives reduction, preheader is modified.
7171
;
7272
; CHECK-LABEL: for.body11.lr.ph:
73-
; CHECK-PRE-LLVM-14: [[GEP1:%.*]] = getelementptr float, float addrspace(1)* %b, i32 [[MUL]]
74-
; CHECK-LLVM-14-PLUS: [[GEP1:%.*]] = getelementptr float, float addrspace(1)* %b, i64 [[ZEXT]]
73+
; CHECK: [[GEP1:%.*]] = getelementptr float, float addrspace(1)* %b, i64 [[ZEXT]]
7574
; CHECK: br label %for.body11
7675
for.body11.lr.ph: ; preds = %for.cond7.preheader
7776
%mul13 = mul nsw i32 %j.07, 10

IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_addexpr.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ entry:
3838
; CHECK: [[ADD1:%.*]] = add i32 %b, %a
3939
; CHECK: [[MUL:%.*]] = mul i32 %c, [[ADD1]]
4040
; CHECK: [[ADD2:%.*]] = add i32 [[ADD1]], [[MUL]]
41-
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i32 [[ADD2]]
41+
; CHECK: [[ZEXT:%.*]] = zext i32 [[ADD2]] to i64
42+
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[ZEXT]]
4243
; CHECK: br label %for.body
4344
for.body.lr.ph: ; preds = %entry
4445
br label %for.body

IGC/Compiler/tests/GEPLoopStrengthReduction/three_accesses_addexpr.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ entry:
4545
br i1 %cmp33, label %for.body.lr.ph, label %for.end
4646

4747
; CHECK-LABEL: for.body.lr.ph:
48-
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i32 %add4.i.i.i
48+
; CHECK: [[ZEXT:%.*]] = zext i32 %add4.i.i.i to i64
49+
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[ZEXT]]
4950
; CHECK: br label %for.body
5051
for.body.lr.ph: ; preds = %entry
5152
br label %for.body

IGC/Compiler/tests/GEPLoopStrengthReduction/two_accesses_licm.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ entry:
3333

3434
; CHECK-LABEL: for.body.lr.ph:
3535
; CHECK: [[ADD:%.*]] = add i32 %delta, 2
36-
; CHECK: [[GEP1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i32 [[ADD]]
36+
; CHECK: [[ZEXT:%.*]] = zext i32 [[ADD]] to i64
37+
; CHECK: [[GEP1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[ZEXT]]
3738
; CHECK: br label %for.body
3839
for.body.lr.ph: ; preds = %entry
3940
br label %for.body

0 commit comments

Comments
 (0)