Skip to content

Commit

Permalink
GEP Loop Strength Reduction pass - don't truncate index type
Browse files Browse the repository at this point in the history
Don't truncate index type when inserting new GEP instructions.

(cherry picked from commit 3afd57f)
  • Loading branch information
pkwasnie-intel authored and pszymich committed Dec 20, 2023
1 parent 46bd9a4 commit 0c02929
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,9 @@ void Analyzer::analyzeGEP(GetElementPtrInst *GEP)
if (!deconstructSCEV(S, Start, Step))
return;

if (S->getType() != Start->getType())
Start = SE.getZeroExtendExpr(Start, S->getType());

// Try adding reduction to existing group
for (auto &c : Candidates)
{
Expand Down Expand Up @@ -908,6 +911,7 @@ bool Analyzer::doInitialValidation(GetElementPtrInst *GEP)
// parsed and reduced.
bool Analyzer::deconstructSCEV(const SCEV *S, const SCEV *&Start, int64_t &Step)
{
// Drop ext instructions to analyze nested content.
S = SCEVHelper::dropExt(S);

// First check if expression can be fully expanded in preheader. If so, no need
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;============================ end_copyright_notice =============================

; REQUIRES: regkeys
; 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%
; RUN: igc_opt --regkey=GEPLSRNewInstructionThreshold=0 -debugify --igc-gep-loop-strength-reduction -check-debugify -S < %s 2>&1 | FileCheck %s
;
; Input:
;
Expand Down Expand Up @@ -51,7 +51,7 @@ for.cond1.preheader.lr.ph: ; preds = %entry
; CHECK-LABEL: for.cond1.preheader:
; CHECK: %j.07 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %inc27, %for.inc26 ]
; CHECK: [[MUL:%.*]] = mul i32 %j.07, 10
; CHECK-LLVM-14-PLUS: [[ZEXT:%.*]] = zext i32 [[MUL]] to i64
; CHECK: [[ZEXT:%.*]] = zext i32 [[MUL]] to i64
; CHECK: br i1 true, label %for.body4.lr.ph, label %for.cond7.preheader
for.cond1.preheader: ; preds = %for.cond1.preheader.lr.ph, %for.inc26
%j.07 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %inc27, %for.inc26 ]
Expand All @@ -70,8 +70,7 @@ for.cond7.preheader: ; preds = %for.cond1.for.cond7
; Loop k2 receives reduction, preheader is modified.
;
; CHECK-LABEL: for.body11.lr.ph:
; CHECK-PRE-LLVM-14: [[GEP1:%.*]] = getelementptr float, float addrspace(1)* %b, i32 [[MUL]]
; CHECK-LLVM-14-PLUS: [[GEP1:%.*]] = getelementptr float, float addrspace(1)* %b, i64 [[ZEXT]]
; CHECK: [[GEP1:%.*]] = getelementptr float, float addrspace(1)* %b, i64 [[ZEXT]]
; CHECK: br label %for.body11
for.body11.lr.ph: ; preds = %for.cond7.preheader
%mul13 = mul nsw i32 %j.07, 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ entry:
; CHECK: [[ADD1:%.*]] = add i32 %b, %a
; CHECK: [[MUL:%.*]] = mul i32 %c, [[ADD1]]
; CHECK: [[ADD2:%.*]] = add i32 [[ADD1]], [[MUL]]
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i32 [[ADD2]]
; CHECK: [[ZEXT:%.*]] = zext i32 [[ADD2]] to i64
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[ZEXT]]
; CHECK: br label %for.body
for.body.lr.ph: ; preds = %entry
br label %for.body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ entry:
br i1 %cmp33, label %for.body.lr.ph, label %for.end

; CHECK-LABEL: for.body.lr.ph:
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i32 %add4.i.i.i
; CHECK: [[ZEXT:%.*]] = zext i32 %add4.i.i.i to i64
; CHECK: [[GEP_PHI1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[ZEXT]]
; CHECK: br label %for.body
for.body.lr.ph: ; preds = %entry
br label %for.body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ entry:

; CHECK-LABEL: for.body.lr.ph:
; CHECK: [[ADD:%.*]] = add i32 %delta, 2
; CHECK: [[GEP1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i32 [[ADD]]
; CHECK: [[ZEXT:%.*]] = zext i32 [[ADD]] to i64
; CHECK: [[GEP1:%.*]] = getelementptr i32, i32 addrspace(1)* %p, i64 [[ZEXT]]
; CHECK: br label %for.body
for.body.lr.ph: ; preds = %entry
br label %for.body
Expand Down

0 comments on commit 0c02929

Please sign in to comment.