summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mlir/lib/IR/AsmPrinter.cpp6
-rw-r--r--mlir/test/IR/affine-map.mlir7
2 files changed, 12 insertions, 1 deletions
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 7d3293ccf00..ada8f1cebd8 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -723,7 +723,11 @@ void ModulePrinter::printAffineExprInternal(
if (rrhs.getValue() == -1) {
printAffineExprInternal(binOp.getLHS(), BindingStrength::Weak);
os << " - ";
- printAffineExprInternal(rhs.getLHS(), BindingStrength::Weak);
+ if (rhs.getLHS().getKind() == AffineExprKind::Add) {
+ printAffineExprInternal(rhs.getLHS(), BindingStrength::Strong);
+ } else {
+ printAffineExprInternal(rhs.getLHS(), BindingStrength::Weak);
+ }
if (enclosingTightness == BindingStrength::Strong)
os << ')';
diff --git a/mlir/test/IR/affine-map.mlir b/mlir/test/IR/affine-map.mlir
index 5f049c93d61..8dffbdfedf6 100644
--- a/mlir/test/IR/affine-map.mlir
+++ b/mlir/test/IR/affine-map.mlir
@@ -175,6 +175,10 @@
// CHECK: #map{{[0-9]+}} = (d0) -> (-2, 1, -1)
#map51 = (i) -> (-5 floordiv 3, -5 mod 3, -5 ceildiv 3)
+// Parenthesis ellision.
+// CHECK: #map{{[0-9]+}} = (d0) -> (d0 * 16 - (d0 + 1) + 15)
+#map52 = (d0) -> (16*d0 + ((d0 + 1) * -1) + 15)
+
// CHECK: extfunc @f0(memref<2x4xi8, #map{{[0-9]+}}, 1>)
extfunc @f0(memref<2x4xi8, #map0, 1>)
@@ -345,3 +349,6 @@ extfunc @f50(memref<100x100xi8, #map50>)
// CHECK: extfunc @f51(memref<1xi8, #map{{[0-9]+}}>)
extfunc @f51(memref<1xi8, #map51>)
+
+// CHECK: extfunc @f52(memref<1xi8, #map{{[0-9]+}}>)
+extfunc @f52(memref<1xi8, #map52>)
OpenPOWER on IntegriCloud