File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -680,10 +680,11 @@ OpFoldResult IntDivOp::fold(FoldAdaptor adaptor) {
680680 return getInput1 ();
681681 }
682682
683- if (rhsAttr && lhsAttr && rhsAttr.isSplat () && lhsAttr.isSplat ()) {
684- if (llvm::isa<IntegerType>(resultETy)) {
685- APInt l = lhsAttr.getSplatValue <APInt>();
686- APInt r = rhsAttr.getSplatValue <APInt>();
683+ if (rhsAttr && lhsAttr && rhsAttr.isSplat () && lhsAttr.isSplat () &&
684+ llvm::isa<IntegerType>(resultETy)) {
685+ APInt l = lhsAttr.getSplatValue <APInt>();
686+ APInt r = rhsAttr.getSplatValue <APInt>();
687+ if (!r.isZero ()) {
687688 APInt result = l.sdiv (r);
688689 return DenseElementsAttr::get (resultTy, result);
689690 }
Original file line number Diff line number Diff line change @@ -1012,3 +1012,14 @@ func.func nested @do_not_fold_reciprocal_int() -> tensor<3x600x1200xi32> {
10121012 %2 = " tosa.reciprocal" (%1 ): (tensor <3 x600 x1200 xi32 >) -> tensor <3 x600 x1200 xi32 >
10131013 return %2 : tensor <3 x600 x1200 xi32 >
10141014}
1015+
1016+ // -----
1017+
1018+ // CHECK-LABEL: @do_not_fold_int_div_division_by_0
1019+ func.func @do_not_fold_int_div_division_by_0 () -> tensor <1 x24 x2 xi32 > {
1020+ // CHECK: tosa.int_div
1021+ %1 = " tosa.const" () <{value = dense <0 > : tensor <1 x24 x2 xi32 >}> : () -> tensor <1 x24 x2 xi32 >
1022+ %4 = " tosa.const" () <{value = dense <20 > : tensor <1 x24 x2 xi32 >}> : () -> tensor <1 x24 x2 xi32 >
1023+ %16 = tosa.int_div %4 , %1 : (tensor <1 x24 x2 xi32 >, tensor <1 x24 x2 xi32 >) -> tensor <1 x24 x2 xi32 >
1024+ return %16 : tensor <1 x24 x2 xi32 >
1025+ }
You can’t perform that action at this time.
0 commit comments