Skip to content

Commit

Permalink
Fix asm printer for affine expr
Browse files Browse the repository at this point in the history
- fixes tensorflow/mlir#201

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Closes tensorflow/mlir#204

COPYBARA_INTEGRATE_REVIEW=tensorflow/mlir#204 from bondhugula:printfix 3f8a5b65391f45598258b2735fecaa409fbde848
PiperOrigin-RevId: 279115720
  • Loading branch information
bondhugula authored and tensorflower-gardener committed Nov 7, 2019
1 parent 8f00b44 commit eb47d5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mlir/lib/IR/AsmPrinter.cpp
Expand Up @@ -1182,9 +1182,12 @@ void ModulePrinter::printAffineExprInternal(

// Pretty print multiplication with -1.
auto rhsConst = rhsExpr.dyn_cast<AffineConstantExpr>();
if (rhsConst && rhsConst.getValue() == -1) {
if (rhsConst && binOp.getKind() == AffineExprKind::Mul &&
rhsConst.getValue() == -1) {
os << "-";
printAffineExprInternal(lhsExpr, BindingStrength::Strong, printValueName);
if (enclosingTightness == BindingStrength::Strong)
os << ')';
return;
}

Expand Down
6 changes: 6 additions & 0 deletions mlir/test/IR/affine-map.mlir
Expand Up @@ -174,6 +174,9 @@
// CHECK: #map{{[0-9]+}} = (d0) -> (d0 - (d0 + 1))
#map53 = (d0) -> (d0 - (d0 + 1))

// CHECK: #map{{[0-9]+}} = (d0)[s0] -> ((-s0) floordiv 4, d0 floordiv -1)
#map54 = (d0)[s0] -> (-s0 floordiv 4, d0 floordiv -1)

// Single identity maps are removed.
// CHECK: func @f0(memref<2x4xi8, 1>)
func @f0(memref<2x4xi8, #map0, 1>)
Expand Down Expand Up @@ -343,3 +346,6 @@ func @f52(memref<1xi8, #map52>)

// CHECK: func @f53(memref<1xi8, #map{{[0-9]+}}>)
func @f53(memref<1xi8, #map53>)

// CHECK: func @f54(memref<10xi32, #map{{[0-9]+}}>)
func @f54(memref<10xi32, #map54>)

0 comments on commit eb47d5e

Please sign in to comment.