File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -878,8 +878,9 @@ OpFoldResult ReshapeOp::fold(FoldAdaptor adaptor) {
878878OpFoldResult PadOp::fold (FoldAdaptor adaptor) {
879879 // If the pad is all zeros we can fold this operation away.
880880 if (adaptor.getPadding () && getInput1 ().getType () == getType ()) {
881- auto densePad = llvm::cast<DenseElementsAttr>(adaptor.getPadding ());
882- if (densePad.isSplat () && densePad.getSplatValue <APInt>().isZero ()) {
881+ auto densePad = llvm::dyn_cast<DenseElementsAttr>(adaptor.getPadding ());
882+ if (densePad && densePad.isSplat () &&
883+ densePad.getSplatValue <APInt>().isZero ()) {
883884 return getInput1 ();
884885 }
885886 }
Original file line number Diff line number Diff line change @@ -217,6 +217,17 @@ func.func @pad_noop(%arg0: tensor<?x?xf32>) -> tensor<?x?xf32> {
217217
218218// -----
219219
220+ // CHECK-LABEL: @pad_noop_padding_mismatch_nofold
221+ func.func @pad_noop_padding_mismatch_nofold (%arg0: tensor <?x?xf32 >) -> tensor <?x?xf32 > {
222+ // CHECK: %[[PAD:.+]] = tosa.pad
223+ // CHECK: return %[[PAD]]
224+ %0 = " tosa.const" () { value = dense_resource<__elided__ > : tensor <2 x2 xi32 >} : () -> tensor <2 x2 xi32 >
225+ %1 = tosa.pad %arg0 , %0 : (tensor <?x?xf32 >, tensor <2 x2 xi32 >) -> tensor <?x?xf32 >
226+ return %1 : tensor <?x?xf32 >
227+ }
228+
229+ // -----
230+
220231// CHECK-LABEL: @pad_noop_type_mismatch_nofold
221232func.func @pad_noop_type_mismatch_nofold (%arg0: tensor <10 xf32 >) -> tensor <?xf32 > {
222233 // CHECK: %[[PAD:.+]] = tosa.pad
You can’t perform that action at this time.
0 commit comments