Skip to content

Commit d6e2aee

Browse files
authored
Revert "[tosa]: canonicalize dynamic size of tosa.slice to static output shape" (#135525)
Reverts #135429 due buildbot breakage: https://lab.llvm.org/buildbot/#/builders/169/builds/10405 Based on the ASan output, I think after the replaceOp on line 775, it's no longer valid to do getSize() on sliceOp: ``` 775 rewriter.replaceOp(sliceOp, newSliceOp.getResult()); 776 777 // Remove const_shape size op when it no longer has use point. 778 Operation *sizeConstShape = sliceOp.getSize().getDefiningOp(); ```
1 parent f4fba20 commit d6e2aee

File tree

2 files changed

+1
-69
lines changed

2 files changed

+1
-69
lines changed

mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -731,62 +731,9 @@ struct ConcatSliceOptimization : public OpRewritePattern<tosa::SliceOp> {
731731
}
732732
};
733733

734-
// Update size operand of tosa.slice if size has dynamic dims but corresponding
735-
// output dim is static
736-
struct SliceDynamicSizeCanonicalization
737-
: public OpRewritePattern<tosa::SliceOp> {
738-
using OpRewritePattern<tosa::SliceOp>::OpRewritePattern;
739-
740-
LogicalResult matchAndRewrite(tosa::SliceOp sliceOp,
741-
PatternRewriter &rewriter) const override {
742-
ShapedType resultType = cast<ShapedType>(sliceOp.getType());
743-
744-
ElementsAttr sizeElems;
745-
if (!matchPattern(sliceOp.getSize(), m_Constant(&sizeElems))) {
746-
return rewriter.notifyMatchFailure(
747-
sliceOp, "size of slice must be a static ranked shape");
748-
}
749-
750-
llvm::SmallVector<int64_t> sliceSizes =
751-
llvm::to_vector(sizeElems.getValues<int64_t>());
752-
753-
bool replaceSliceSize{false};
754-
// if size op has -1 indicating dynamic shape but corresponding dim on the
755-
// output is statically known, update size to match with known output dim
756-
// shape
757-
for (const auto &[index, size] : llvm::enumerate(sliceSizes)) {
758-
if (size == -1 && !resultType.isDynamicDim(index)) {
759-
sliceSizes[index] = resultType.getDimSize(index);
760-
replaceSliceSize = true;
761-
}
762-
}
763-
764-
if (!replaceSliceSize) {
765-
return rewriter.notifyMatchFailure(
766-
sliceOp, "no dimension of size of slice is dynamic that resolves "
767-
"to static output shape");
768-
}
769-
770-
auto size_op = getTosaConstShape(rewriter, sliceOp.getLoc(), sliceSizes);
771-
auto newSliceOp = rewriter.create<tosa::SliceOp>(
772-
sliceOp.getLoc(), sliceOp.getType(), sliceOp.getInput1(),
773-
sliceOp.getStart(), size_op);
774-
775-
rewriter.replaceOp(sliceOp, newSliceOp.getResult());
776-
777-
// Remove const_shape size op when it no longer has use point.
778-
Operation *sizeConstShape = sliceOp.getSize().getDefiningOp();
779-
if (sizeConstShape->getResult(0).hasOneUse())
780-
rewriter.eraseOp(sizeConstShape);
781-
782-
return success();
783-
}
784-
};
785-
786734
void SliceOp::getCanonicalizationPatterns(RewritePatternSet &results,
787735
MLIRContext *context) {
788-
results.add<ConcatSliceOptimization, SliceDynamicSizeCanonicalization>(
789-
context);
736+
results.add<ConcatSliceOptimization>(context);
790737
}
791738

792739
//===----------------------------------------------------------------------===//

mlir/test/Dialect/Tosa/canonicalize.mlir

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,18 +1212,3 @@ func.func @do_not_fold_intdiv_division_by_0() -> tensor<1x24x2xi32> {
12121212
%16 = tosa.intdiv %4, %1 : (tensor<1x24x2xi32>, tensor<1x24x2xi32>) -> tensor<1x24x2xi32>
12131213
return %16 : tensor<1x24x2xi32>
12141214
}
1215-
1216-
1217-
// ----
1218-
// CHECK-LABEL: func.func @slice_dynamic_size_static_output_canonicalize(
1219-
// CHECK-SAME: %[[ARG0:.*]]: tensor<2x60x59x?xf32>) -> tensor<2x60x58x?xf32> {
1220-
// CHECK: %[[START:.*]] = tosa.const_shape {values = dense<0> : tensor<4xindex>} : () -> !tosa.shape<4>
1221-
// CHECK: %[[SIZE:.*]] = tosa.const_shape {values = dense<[2, 60, 58, -1]> : tensor<4xindex>} : () -> !tosa.shape<4>
1222-
// CHECK: %[[SLICE:.*]] = tosa.slice %[[ARG0]], %[[START]], %[[SIZE]] : (tensor<2x60x59x?xf32>, !tosa.shape<4>, !tosa.shape<4>) -> tensor<2x60x58x?xf32>
1223-
// CHECK: return %[[SLICE]]
1224-
func.func @slice_dynamic_size_static_output_canonicalize(%arg0: tensor<2x60x59x?xf32>) -> tensor<2x60x58x?xf32> {
1225-
%0 = tosa.const_shape {values = dense<0> : tensor<4xindex>} : () -> !tosa.shape<4>
1226-
%1 = tosa.const_shape {values = dense<[-1, 60, 58, -1]> : tensor<4xindex>} : () -> !tosa.shape<4>
1227-
%2 = tosa.slice %arg0, %0, %1 : (tensor<2x60x59x?xf32>, !tosa.shape<4>, !tosa.shape<4>) -> tensor<2x60x58x?xf32>
1228-
return %2 : tensor<2x60x58x?xf32>
1229-
}

0 commit comments

Comments
 (0)