@@ -1147,3 +1147,59 @@ func.func @canonicalize_select_lrelu_zero_pattern(%arg0: tensor<13x21x3xf32>) ->
1147
1147
return %3 : tensor <13 x21 x3 xf32 >
1148
1148
}
1149
1149
1150
+ // -----
1151
+
1152
+ // CHECK-LABEL: @canonicalize_select_to_clamp_i64_and_i8_pat1
1153
+ func.func @canonicalize_select_to_clamp_i64_and_i8_pat1 (%arg0: tensor <13 x21 x3 xi64 >, %arg1: tensor <13 x21 x3 xi8 >) -> tensor <13 x21 x3 xi8 > {
1154
+ // CHECK: %[[VAL_1:.*]] = tosa.cast %arg{{.*}} : (tensor<13x21x3xi64>) -> tensor<13x21x3xi8>
1155
+ // CHECK: %[[VAL_2:.*]] = tosa.clamp %[[VAL_1]] {max_fp = 0x7F800000 : f32, max_int = 9223372036854775807 : i64, min_fp = 0xFF800000 : f32, min_int = 42 : i64} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi8>
1156
+ // CHECK: return %[[VAL_2]] : tensor<13x21x3xi8>
1157
+ %0 = " tosa.const" () <{value = dense <42 > : tensor <13 x21 x3 xi64 >}>: () -> tensor <13 x21 x3 xi64 >
1158
+ %1 = " tosa.const" () <{value = dense <42 > : tensor <13 x21 x3 xi8 >}>: () -> tensor <13 x21 x3 xi8 >
1159
+ %2 = tosa.greater_equal %arg0 , %0: (tensor <13 x21 x3 xi64 >, tensor <13 x21 x3 xi64 >) -> tensor <13 x21 x3 xi1 >
1160
+ %3 = tosa.select %2 , %arg1 , %1: ( tensor <13 x21 x3 xi1 >, tensor <13 x21 x3 xi8 >, tensor <13 x21 x3 xi8 >) -> tensor <13 x21 x3 xi8 >
1161
+ return %3 : tensor <13 x21 x3 xi8 >
1162
+ }
1163
+
1164
+ // -----
1165
+
1166
+ // CHECK-LABEL: @canonicalize_select_to_clamp_i64_and_i8_pat2
1167
+ func.func @canonicalize_select_to_clamp_i64_and_i8_pat2 (%arg0: tensor <13 x21 x3 xi64 >, %arg1: tensor <13 x21 x3 xi8 >) -> tensor <13 x21 x3 xi8 > {
1168
+ // CHECK: %[[VAL_1:.*]] = tosa.cast %arg{{.*}} : (tensor<13x21x3xi64>) -> tensor<13x21x3xi8>
1169
+ // CHECK: %[[VAL_2:.*]] = tosa.clamp %[[VAL_1]] {max_fp = 0x7F800000 : f32, max_int = -42 : i64, min_fp = 0xFF800000 : f32, min_int = -9223372036854775808 : i64} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi8>
1170
+ // CHECK: return %[[VAL_2]] : tensor<13x21x3xi8>
1171
+ %0 = " tosa.const" () <{value = dense <-42 > : tensor <13 x21 x3 xi64 >}>: () -> tensor <13 x21 x3 xi64 >
1172
+ %1 = " tosa.const" () <{value = dense <-42 > : tensor <13 x21 x3 xi8 >}>: () -> tensor <13 x21 x3 xi8 >
1173
+ %2 = tosa.greater_equal %arg0 , %0: (tensor <13 x21 x3 xi64 >, tensor <13 x21 x3 xi64 >) -> tensor <13 x21 x3 xi1 >
1174
+ %3 = tosa.select %2 , %1 , %arg1 : ( tensor <13 x21 x3 xi1 >, tensor <13 x21 x3 xi8 >, tensor <13 x21 x3 xi8 >) -> tensor <13 x21 x3 xi8 >
1175
+ return %3 : tensor <13 x21 x3 xi8 >
1176
+ }
1177
+
1178
+ // -----
1179
+
1180
+ // CHECK-LABEL: @canonicalize_select_to_clamp_i8_and_i64_pat1
1181
+ func.func @canonicalize_select_to_clamp_i8_and_i64_pat1 (%arg0: tensor <13 x21 x3 xi8 >, %arg1: tensor <13 x21 x3 xi64 >) -> tensor <13 x21 x3 xi64 > {
1182
+ // CHECK: %[[VAL_1:.*]] = tosa.cast %arg{{.*}} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi64>
1183
+ // CHECK: %[[VAL_2:.*]] = tosa.clamp %[[VAL_1]] {max_fp = 0x7F800000 : f32, max_int = 9223372036854775807 : i64, min_fp = 0xFF800000 : f32, min_int = 42 : i64} : (tensor<13x21x3xi64>) -> tensor<13x21x3xi64>
1184
+ // CHECK: return %[[VAL_2]] : tensor<13x21x3xi64>
1185
+ %0 = " tosa.const" () <{value = dense <42 > : tensor <13 x21 x3 xi8 >}>: () -> tensor <13 x21 x3 xi8 >
1186
+ %1 = " tosa.const" () <{value = dense <42 > : tensor <13 x21 x3 xi64 >}>: () -> tensor <13 x21 x3 xi64 >
1187
+ %2 = tosa.greater_equal %arg0 , %0: (tensor <13 x21 x3 xi8 >, tensor <13 x21 x3 xi8 >) -> tensor <13 x21 x3 xi1 >
1188
+ %3 = tosa.select %2 , %arg1 , %1: ( tensor <13 x21 x3 xi1 >, tensor <13 x21 x3 xi64 >, tensor <13 x21 x3 xi64 >) -> tensor <13 x21 x3 xi64 >
1189
+ return %3 : tensor <13 x21 x3 xi64 >
1190
+ }
1191
+
1192
+ // -----
1193
+
1194
+ // CHECK-LABEL: @canonicalize_select_to_clamp_i8_and_i64_pat2
1195
+ func.func @canonicalize_select_to_clamp_i8_and_i64_pat2 (%arg0: tensor <13 x21 x3 xi8 >, %arg1: tensor <13 x21 x3 xi64 >) -> tensor <13 x21 x3 xi64 > {
1196
+ // CHECK: %[[VAL_1:.*]] = tosa.cast %arg{{.*}} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi64>
1197
+ // CHECK: %[[VAL_2:.*]] = tosa.clamp %[[VAL_1]] {max_fp = 0x7F800000 : f32, max_int = -42 : i64, min_fp = 0xFF800000 : f32, min_int = -9223372036854775808 : i64} : (tensor<13x21x3xi64>) -> tensor<13x21x3xi64>
1198
+ // CHECK: return %[[VAL_2]] : tensor<13x21x3xi64>
1199
+ %0 = " tosa.const" () <{value = dense <-42 > : tensor <13 x21 x3 xi8 >}>: () -> tensor <13 x21 x3 xi8 >
1200
+ %1 = " tosa.const" () <{value = dense <-42 > : tensor <13 x21 x3 xi64 >}>: () -> tensor <13 x21 x3 xi64 >
1201
+ %2 = tosa.greater_equal %arg0 , %0: (tensor <13 x21 x3 xi8 >, tensor <13 x21 x3 xi8 >) -> tensor <13 x21 x3 xi1 >
1202
+ %3 = tosa.select %2 , %1 , %arg1: ( tensor <13 x21 x3 xi1 >, tensor <13 x21 x3 xi64 >, tensor <13 x21 x3 xi64 >) -> tensor <13 x21 x3 xi64 >
1203
+ return %3 : tensor <13 x21 x3 xi64 >
1204
+ }
1205
+
0 commit comments