From 4e6dc0d7b278dcfb693319afdef73eecea3d662f Mon Sep 17 00:00:00 2001 From: Weiming Zhao Date: Mon, 29 Nov 2021 21:21:00 +0000 Subject: [PATCH] [Fix] slice with dynamic batch When the length operand of slice is -1, it means taking all elements on that dimension. Originally, inst simplification pass attemps to replace -1 with actual dimension size. However, -1 is also used to represent dynamic size, so it will make the pass keep running. --- lib/transforms/inst_simplify.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/transforms/inst_simplify.cc b/lib/transforms/inst_simplify.cc index 680262974..3b3e75e68 100644 --- a/lib/transforms/inst_simplify.cc +++ b/lib/transforms/inst_simplify.cc @@ -2324,9 +2324,10 @@ std::pair InstSimplify::RunOnInstruction(SliceInst* inst) { std::vector size_adj(dim); bool new_size = false; for (int i = 0; i != dim; ++i) { - int size_i = c_size->GetDataAsInt64(i); - if (size_i == -1) { - size_adj[i] = dst_type.GetNumOfElementsInDim(i); + int64_t size_i = c_size->GetDataAsInt64(i); + int64_t s = dst_type.GetNumOfElementsInDim(i); + if (size_i == -1 && s != -1) { + size_adj[i] = s; new_size = true; } else { size_adj[i] = size_i;