File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -393,8 +393,12 @@ void arith::AddUIExtendedOp::getCanonicalizationPatterns(
393393
394394OpFoldResult arith::SubIOp::fold (FoldAdaptor adaptor) {
395395 // subi(x,x) -> 0
396- if (getOperand (0 ) == getOperand (1 ))
397- return Builder (getContext ()).getZeroAttr (getType ());
396+ if (getOperand (0 ) == getOperand (1 )) {
397+ auto tensorType = dyn_cast<TensorType>(getType ());
398+ // We can't generate a constant with a dynamic shaped tensor.
399+ if (!tensorType || tensorType.hasStaticShape ())
400+ return Builder (getContext ()).getZeroAttr (getType ());
401+ }
398402 // subi(x,0) -> x
399403 if (matchPattern (adaptor.getRhs (), m_Zero ()))
400404 return getLhs ();
Original file line number Diff line number Diff line change @@ -869,6 +869,17 @@ func.func @tripleAddAddOvf2(%arg0: index) -> index {
869869 return %add2 : index
870870}
871871
872+
873+ // CHECK-LABEL: @foldSubXX
874+ // CHECK: %[[c0:.+]] = arith.constant dense<0> : tensor<10xi32>
875+ // CHECK: %[[sub:.+]] = arith.subi
876+ // CHECK: return %[[c0]], %[[sub]]
877+ func.func @foldSubXX (%dyn : tensor <?x?xi32 >, %static : tensor <10 xi32 >) -> (tensor <10 xi32 >, tensor <?x?xi32 >) {
878+ %static_sub = arith.subi %static , %static : tensor <10 xi32 >
879+ %dyn_sub = arith.subi %dyn , %dyn : tensor <?x?xi32 >
880+ return %static_sub , %dyn_sub : tensor <10 xi32 >, tensor <?x?xi32 >
881+ }
882+
872883// CHECK-LABEL: @tripleAddSub0
873884// CHECK: %[[cres:.+]] = arith.constant 59 : index
874885// CHECK: %[[add:.+]] = arith.subi %[[cres]], %arg0 : index
You can’t perform that action at this time.
0 commit comments