File tree 2 files changed +27
-4
lines changed
include/mlir/Dialect/Tosa/IR
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -1728,8 +1728,7 @@ def Tosa_ReduceMaxOp : Tosa_InferTensorTypeOp<"reduce_max"> {
1728
1728
1729
1729
/// Return the max of the two integer operands
1730
1730
static inline APInt calcOneElement(APInt leftOperand, APInt rightOperand) {
1731
- const llvm::APInt subtractRes = leftOperand - rightOperand;
1732
- return (!subtractRes.isNegative()) ? leftOperand : rightOperand;
1731
+ return (leftOperand.sge(rightOperand)) ? leftOperand : rightOperand;
1733
1732
}
1734
1733
}];
1735
1734
}
@@ -1769,8 +1768,7 @@ def Tosa_ReduceMinOp : Tosa_InferTensorTypeOp<"reduce_min"> {
1769
1768
1770
1769
/// Return the min of the two integer operands
1771
1770
static inline APInt calcOneElement(APInt leftOperand, APInt rightOperand) {
1772
- const llvm::APInt subtractRes = leftOperand - rightOperand;
1773
- return (!subtractRes.isNegative()) ? rightOperand : leftOperand;
1771
+ return (leftOperand.sle(rightOperand)) ? leftOperand : rightOperand;
1774
1772
}
1775
1773
}];
1776
1774
}
Original file line number Diff line number Diff line change @@ -883,6 +883,18 @@ func.func @reduce_max_constant() -> tensor<1x1x1xi32> {
883
883
return %0 : tensor <1 x1 x1 xi32 >
884
884
}
885
885
886
+ // -----
887
+
888
+ func.func @reduce_max_constant_no_overflow () -> tensor <1 xi8 > {
889
+ // CHECK-LABEL: func.func @reduce_max_constant_no_overflow() -> tensor<1xi8> {
890
+ // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<120> : tensor<1xi8>}> : () -> tensor<1xi8>
891
+ // CHECK: return %[[VAL_0]] : tensor<1xi8>
892
+ // CHECK: }
893
+ %const = " tosa.const" () <{values = dense <[-127 , 120 , -126 ]> : tensor <3 xi8 >}> : () -> tensor <3 xi8 >
894
+ %0 = tosa.reduce_max %const {axis = 0 : i32 } : (tensor <3 xi8 >) -> tensor <1 xi8 >
895
+ return %0 : tensor <1 xi8 >
896
+ }
897
+
886
898
// -----
887
899
888
900
func.func @reduce_min_constant () -> tensor <1 x3 xi32 > {
@@ -968,6 +980,19 @@ func.func @reduce_min_constant() -> tensor<1x1x1xi32> {
968
980
return %0 : tensor <1 x1 x1 xi32 >
969
981
}
970
982
983
+ // -----
984
+
985
+ func.func @reduce_min_constant_no_overflow () -> tensor <1 xi8 > {
986
+ // CHECK-LABEL: func.func @reduce_min_constant_no_overflow() -> tensor<1xi8> {
987
+ // CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<-127> : tensor<1xi8>}> : () -> tensor<1xi8>
988
+ // CHECK: return %[[VAL_0]] : tensor<1xi8>
989
+ // CHECK: }
990
+ %const = " tosa.const" () <{values = dense <[-127 , 120 , -126 ]> : tensor <3 xi8 >}> : () -> tensor <3 xi8 >
991
+ %0 = tosa.reduce_min %const {axis = 0 : i32 } : (tensor <3 xi8 >) -> tensor <1 xi8 >
992
+ return %0 : tensor <1 xi8 >
993
+ }
994
+
995
+
971
996
// -----
972
997
973
998
func.func @reduce_any_constant () -> tensor <1 x3 xi1 > {
You can’t perform that action at this time.
0 commit comments