File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
include/mlir/Dialect/Tosa/IR Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -1731,8 +1731,7 @@ def Tosa_ReduceMaxOp : Tosa_InferTensorTypeOp<"reduce_max"> {
1731
1731
1732
1732
/// Return the max of the two integer operands
1733
1733
static inline APInt calcOneElement(APInt leftOperand, APInt rightOperand) {
1734
- const llvm::APInt subtractRes = leftOperand - rightOperand;
1735
- return (!subtractRes.isNegative()) ? leftOperand : rightOperand;
1734
+ return (leftOperand.sge(rightOperand)) ? leftOperand : rightOperand;
1736
1735
}
1737
1736
}];
1738
1737
}
@@ -1772,8 +1771,7 @@ def Tosa_ReduceMinOp : Tosa_InferTensorTypeOp<"reduce_min"> {
1772
1771
1773
1772
/// Return the min of the two integer operands
1774
1773
static inline APInt calcOneElement(APInt leftOperand, APInt rightOperand) {
1775
- const llvm::APInt subtractRes = leftOperand - rightOperand;
1776
- return (!subtractRes.isNegative()) ? rightOperand : leftOperand;
1774
+ return (leftOperand.sle(rightOperand)) ? leftOperand : rightOperand;
1777
1775
}
1778
1776
}];
1779
1777
}
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