Issue 170849
Summary MLIR Python binding rejects valid MLIR program (tosa.cond_if) that mliropt parses successfully
Labels mlir
Assignees
Reporter Subway2023
    # πŸ“Œ **Summary**

MLIR C++ frontend (`mliropt`) successfully parses a valid TOSA program using `tosa.cond_if`.

However, the same program fails when parsed using MLIR’s Python bindings via:

```python
module = ir.Module.parse(text)
```

The Python binding incorrectly reports a type inconsistency between `tensor<i1>` and `tensor<1xi1>` for the same SSA value, even though the MLIR program is valid and works in the C++ toolchain.

This appears to be a **Python MLIR parser bug**, not an issue with the MLIR IR.

---

# πŸ“Œ **Environment**

* MLIR version: 21.1.2
---

# πŸ“Œ **Reproducer**

### **Python code**

```python
from mlir import ir

original_text = """
module {
  func.func @main() -> tensor<i32> {
    %true = arith.constant true
    %from_elements = tensor.from_elements %true : tensor<1xi1>
    %c42_i32 = arith.constant 42 : i32
    %from_elements_0 = tensor.from_elements %c42_i32 : tensor<i32>
    %0 = tosa.cond_if %from_elements -> (tensor<i32>) {
      %c100_i32 = arith.constant 100 : i32
      %from_elements_1 = tensor.from_elements %c100_i32 : tensor<i32>
      tosa.yield %from_elements_1 : tensor<i32>
    } else {
      %c200_i32 = arith.constant 200 : i32
      %from_elements_1 = tensor.from_elements %c200_i32 : tensor<i32>
      tosa.yield %from_elements_1 : tensor<i32>
    }
    return %0 : tensor<i32>
  }
}
"""

with ir.Context() as ctx:
    module = ir.Module.parse(original_text)
    print(module)
```

### **Result (Python binding error)**

```
mlir._mlir_libs._site_initialize.<locals>.MLIRError: Unable to parse module assembly:
error: "-":8:23: use of value '%from_elements' expects different type than prior uses: 'tensor<i1>' vs 'tensor<1xi1>'
 note: "-":5:5: prior use here
```

---

# πŸ“Œ **BUT the same MLIR parses successfully using mliropt**

Command:

```
mlir-opt tosa.cond_if.mlir
```

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

Reply via email to