diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 51fe49a3c0bf8..16844bd12c413 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -2791,7 +2791,8 @@ void AsmPrinter::Impl::printOptionalAttrDict(ArrayRef attrs, SmallString<16> separator = StringRef(", "); if (printerFlags.getNewlineAfterAttrLimit() && - attrs.size() > *printerFlags.getNewlineAfterAttrLimit()) { + std::distance(filteredAttrs.begin(), filteredAttrs.end()) > + *printerFlags.getNewlineAfterAttrLimit()) { // Increase indent to match the visually match the "{ " below. // currentIndent += 2; diff --git a/mlir/test/IR/mlir-newline-after-attr.mlir b/mlir/test/IR/mlir-newline-after-attr.mlir index d35eac21a5152..047a9257d563c 100644 --- a/mlir/test/IR/mlir-newline-after-attr.mlir +++ b/mlir/test/IR/mlir-newline-after-attr.mlir @@ -29,3 +29,6 @@ // CHECK-NEXT: ], "test.op"() {foo.dense_attr = dense<1> : tensor<3xi32>, foo.second_attr = dense<2> : tensor<3xi32>, Operands = [{foo.vect_attr_1_start = dense<0> : vector<3xindex>, foo.vect_attr_1_end = dense<0> : vector<3xindex>, foo.vect_attr_1_count = dense<1> : vector<3xindex>, foo.vect_attr_2_start = dense<0> : vector<3xindex>, foo.vect_attr_2_end = dense<0> : vector<3xindex>, foo.vect_attr_2_count = dense<1> : vector<3xindex>}, {foo.vect_attr_1_start = dense<0> : vector<3xindex>, foo.vect_attr_1_end = dense<0> : vector<3xindex>, foo.vect_attr_1_count = dense<1> : vector<3xindex>, foo.vect_attr_2_start = dense<0> : vector<3xindex>, foo.vect_attr_2_end = dense<0> : vector<3xindex>, foo.vect_attr_2_count = dense<1> : vector<3xindex>}]} : () -> () +// const_shape skips over shape attr when printing. Check that we do not insert unnecessary newlines +// CHECK{LITERAL}: shape.const_shape {foo.second_attr = dense<2> : tensor<3xi32>, foo.third_attr = dense<2> : tensor<3xi32>}[1, 1, 1] : tensor<3xindex> +"shape.const_shape"() {shape = dense<1> : tensor<3xindex>, foo.second_attr = dense<2> : tensor<3xi32>, foo.third_attr = dense<2> : tensor<3xi32>} : () -> (tensor<3xindex>) \ No newline at end of file