Skip to content

[MLIR] Fold TOSA truthy boolean to i32 with 1 instead of -1 #149009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,8 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor) {

if (trunc) {
intVal = intVal.trunc(bitwidth);
} else if (unsignIn) {
} else if (unsignIn || inETy.getIntOrFloatBitWidth() == 1) {
// Casting from i1 to iX will treat it as unsigned.
intVal = intVal.zext(bitwidth);
} else {
intVal = intVal.sext(bitwidth);
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/Dialect/Tosa/constant-op-fold.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,16 @@ func.func @cast_int_to_int_sign() -> tensor<i32> {
return %cast : tensor<i32>
}


// CHECK: func.func @cast_i1_true_to_i32
func.func @cast_i1_true_to_i32() -> tensor<i32> {
%splat = "tosa.const"() {values = dense<true> : tensor<i1>} : () -> tensor<i1>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<1> : tensor<i32>}
%cast = tosa.cast %splat : (tensor<i1>) -> tensor<i32>
// CHECK: return %[[SPLAT]]
return %cast : tensor<i32>
}

// -----

// CHECK-LABEL: @reverse_splat
Expand Down
Loading