diff --git a/compiler/src/iree/compiler/Codegen/Common/OptimizeTensorInsertExtractSlices.cpp b/compiler/src/iree/compiler/Codegen/Common/OptimizeTensorInsertExtractSlices.cpp index 3ee4b53a2593..2b608be094e8 100644 --- a/compiler/src/iree/compiler/Codegen/Common/OptimizeTensorInsertExtractSlices.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/OptimizeTensorInsertExtractSlices.cpp @@ -108,10 +108,13 @@ hoistLoopInvariantSubsetAtIterArg(RewriterBase &rewriter, ArrayRef innerNewBBArgs) -> SmallVector { return {insertion.getSourceOperand().get()}; }; + + // replaceInitOperandUsesInLoop is set to true S.T we will use new IV + // instead of hoisted out extract. FailureOr newLoop = loopLike.replaceWithAdditionalYields( rewriter, extraction.getResult(), - /*replaceInitOperandUsesInLoop=*/false, newYieldValuesFn); + /*replaceInitOperandUsesInLoop=*/true, newYieldValuesFn); if (failed(newLoop)) return loopLike; loopLike = *newLoop; diff --git a/compiler/src/iree/compiler/Codegen/Common/test/optimize_tensor_insert_extract_slices.mlir b/compiler/src/iree/compiler/Codegen/Common/test/optimize_tensor_insert_extract_slices.mlir index 8a35b4bffa61..2cf5726e84ba 100644 --- a/compiler/src/iree/compiler/Codegen/Common/test/optimize_tensor_insert_extract_slices.mlir +++ b/compiler/src/iree/compiler/Codegen/Common/test/optimize_tensor_insert_extract_slices.mlir @@ -158,9 +158,10 @@ func.func @subset_hoisting_invariant_tensor(%init: tensor<64x64xf32>, %t: tensor // CHECK-LABEL: @subset_hoisting_invariant_tensor // CHECK: tensor.extract_slice -// CHECK: scf.for -// CHECK: tensor.extract_slice +// CHECK: scf.for {{.*}} iter_args(%[[IV:.+]] = {{.*}}) +// CHECK: %[[SLICE:.+]] = tensor.extract_slice // CHECK-NOT: tensor.extract_slice +// CHECK: linalg.add ins(%[[IV]], %[[SLICE]] : {{.*}}) // CHECK: scf.yield // CHECK: tensor.insert_slice