Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,12 @@ OpFoldResult ArgMaxOp::fold(FoldAdaptor adaptor) {
!outputTy.hasStaticShape())
return {};

if (inputTy.getDimSize(getAxis()) == 1)
return DenseElementsAttr::get(outputTy, 0);
const Type outputElementTy = getElementTypeOrSelf(outputTy);
if (inputTy.getDimSize(getAxis()) == 1 && outputElementTy.isInteger()) {
const auto outputElemIntTy = cast<IntegerType>(outputElementTy);
const APInt zero = APInt::getZero(outputElemIntTy.getWidth());
return DenseElementsAttr::get(outputTy, zero);
}

return {};
}
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/Dialect/Tosa/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ func.func @argmax_nofold(%arg0: tensor<?x1xf32>) -> tensor<1xi32> {

// -----

// CHECK-LABEL: @test_argmax_fold_i64_index
func.func @test_argmax_fold_i64_index(%arg0: tensor<1xi8>) -> tensor<i64> {
// CHECK: "tosa.const"() <{values = dense<0> : tensor<i64>}> : () -> tensor<i64>
%0 = tosa.argmax %arg0 {axis = 0 : i32} : (tensor<1xi8>) -> tensor<i64>
return %0 : tensor<i64>
}

// -----

// CHECK-LABEL: @pad_wh_avg_pool2d_fold
func.func @pad_wh_avg_pool2d_fold(%input: tensor<1x10x8x3xf32>) -> tensor<1x6x5x3xf32> {
// CHECK-NOT: tosa.pad
Expand Down