Skip to content

Commit 7e140ac

Browse files
committed
Fix folding i1 true to i32
1 parent 755611c commit 7e140ac

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,8 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor) {
13031303

13041304
if (trunc) {
13051305
intVal = intVal.trunc(bitwidth);
1306-
} else if (unsignIn) {
1306+
} else if (unsignIn || inETy.getIntOrFloatBitWidth() == 1) {
1307+
// Casting from i1 to iX will treat it as unsigned.
13071308
intVal = intVal.zext(bitwidth);
13081309
} else {
13091310
intVal = intVal.sext(bitwidth);

mlir/test/Dialect/Tosa/constant-op-fold.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ func.func @cast_int_to_int_sign() -> tensor<i32> {
598598
// CHECK: func.func @cast_i1_true_to_i32
599599
func.func @cast_i1_true_to_i32() -> tensor<i32> {
600600
%splat = "tosa.const"() {values = dense<true> : tensor<i1>} : () -> tensor<i1>
601-
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-1> : tensor<i32>}
601+
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<1> : tensor<i32>}
602602
%cast = tosa.cast %splat : (tensor<i1>) -> tensor<i32>
603603
// CHECK: return %[[SPLAT]]
604604
return %cast : tensor<i32>

0 commit comments

Comments
 (0)