Issue 172952
Summary [mlir][EmitC] `emitc._expression_` custom print/parse broken in common edge cases
Labels mlir
Assignees
Reporter christopherbate
    Failure can be reproduced by running `mlir-opt` to parse the below generic form of a valid `emitc._expression_`:

```
func.func @test(%arg0: i32) -> i32 {
 %result = "emitc._expression_"(%arg0, %arg0) ({
  ^bb0(%arg1: i32, %arg2: i32):
     %1 = emitc.add %arg1, %arg2 : (i32, i32) -> i32
 emitc.yield %1 : i32
   }) : (i32, i32) -> i32
   return %result : i32
}
```

It will pretty-print this IR which cannot be correctly parsed:

```
func.func @test(%arg0: i32) -> i32 {
   %result = emitc._expression_ %arg0, %arg0 : (i32, i32) -> i32 {
      %1 = emitc.add %arg0, %arg0 : (i32, i32) -> i32
      yield %1 : i32
   }
   return %result : i32
}
```

Note that this is not a contrived example because the formation of `emitc._expression_` is done by a transformation, I observe this edge-case happening in typical code. The workaround I'm using currently is to print the IR in generic from since this only affects roundtripping IR through the pretty-printed format.  

In [this change](https://github.com/llvm/llvm-project/pull/155641), the `emitc._expression_` operation was updated so that it is "isolated-from-above". However, the author used an MLIR ASM printer method [`p.shadowRegionArgs`](https://github.com/search?q=repo%3Allvm%2Fllvm-project%20shadowRegionArgs&type=code) to try to make the `emitc._expression_` region arguments print using the SSA names of the operands.

The `emitc._expression_` operation is the only user of this method in-tree, and the methodology seems suspect because if the operand list contains duplicates, the pretty printed form with "shadowed" names is ambiguous. 


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to