diff --git a/IGC/Compiler/Optimizer/OpenCLPasses/GEPLoopStrengthReduction/GEPLoopStrengthReduction.cpp b/IGC/Compiler/Optimizer/OpenCLPasses/GEPLoopStrengthReduction/GEPLoopStrengthReduction.cpp index 778d2deec0a3..b50989e9fd56 100644 --- a/IGC/Compiler/Optimizer/OpenCLPasses/GEPLoopStrengthReduction/GEPLoopStrengthReduction.cpp +++ b/IGC/Compiler/Optimizer/OpenCLPasses/GEPLoopStrengthReduction/GEPLoopStrengthReduction.cpp @@ -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) { @@ -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 diff --git a/IGC/Compiler/tests/GEPLoopStrengthReduction/heuristic_instruction_count.ll b/IGC/Compiler/tests/GEPLoopStrengthReduction/heuristic_instruction_count.ll index 42908e38088e..a356da2b4edc 100644 --- a/IGC/Compiler/tests/GEPLoopStrengthReduction/heuristic_instruction_count.ll +++ b/IGC/Compiler/tests/GEPLoopStrengthReduction/heuristic_instruction_count.ll @@ -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: ; @@ -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 ] @@ -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 diff --git a/IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_addexpr.ll b/IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_addexpr.ll index f55e2f164e34..c2b08c4bbe49 100644 --- a/IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_addexpr.ll +++ b/IGC/Compiler/tests/GEPLoopStrengthReduction/one_access_addexpr.ll @@ -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 diff --git a/IGC/Compiler/tests/GEPLoopStrengthReduction/three_accesses_addexpr.ll b/IGC/Compiler/tests/GEPLoopStrengthReduction/three_accesses_addexpr.ll index d38a1566b0a8..059cbbab17f6 100644 --- a/IGC/Compiler/tests/GEPLoopStrengthReduction/three_accesses_addexpr.ll +++ b/IGC/Compiler/tests/GEPLoopStrengthReduction/three_accesses_addexpr.ll @@ -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 diff --git a/IGC/Compiler/tests/GEPLoopStrengthReduction/two_accesses_licm.ll b/IGC/Compiler/tests/GEPLoopStrengthReduction/two_accesses_licm.ll index af6effff351a..a33885317a61 100644 --- a/IGC/Compiler/tests/GEPLoopStrengthReduction/two_accesses_licm.ll +++ b/IGC/Compiler/tests/GEPLoopStrengthReduction/two_accesses_licm.ll @@ -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