[Mlir-commits] [mlir] [mlir][tosa] Fix validation check on controlflow operators (PR #159754)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 19 03:50:42 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Luke Hutton (lhutton1)
<details>
<summary>Changes</summary>
Previoulsy the error_if check for controlflow operators would silently fail on valid controflow operators. This was due to incorrect return logic in the validation function. This commit fixes that logic.
---
Full diff: https://github.com/llvm/llvm-project/pull/159754.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp (+4-4)
- (added) mlir/test/Dialect/Tosa/tosa-validation-valid-strict.mlir (+15)
``````````diff
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
index 790bbf77877bc..e6091df367754 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
@@ -1257,8 +1257,8 @@ bool checkErrorIfCondIf(Operation *op) {
// tosa.yield %arg4
// }
- return failed(checkIsolatedRegion(op, ifOp.getThenGraph(), "then")) ||
- failed(checkIsolatedRegion(op, ifOp.getElseGraph(), "else"));
+ return succeeded(checkIsolatedRegion(op, ifOp.getThenGraph(), "then")) &&
+ succeeded(checkIsolatedRegion(op, ifOp.getElseGraph(), "else"));
}
bool checkErrorIfWhileLoop(Operation *op) {
@@ -1266,8 +1266,8 @@ bool checkErrorIfWhileLoop(Operation *op) {
if (!whileOp)
return true;
- return failed(checkIsolatedRegion(op, whileOp.getCondGraph(), "cond")) ||
- failed(checkIsolatedRegion(op, whileOp.getBodyGraph(), "body"));
+ return succeeded(checkIsolatedRegion(op, whileOp.getCondGraph(), "cond")) &&
+ succeeded(checkIsolatedRegion(op, whileOp.getBodyGraph(), "body"));
}
bool checkErrorIfScatter(Operation *op) {
diff --git a/mlir/test/Dialect/Tosa/tosa-validation-valid-strict.mlir b/mlir/test/Dialect/Tosa/tosa-validation-valid-strict.mlir
new file mode 100644
index 0000000000000..fe423104359ab
--- /dev/null
+++ b/mlir/test/Dialect/Tosa/tosa-validation-valid-strict.mlir
@@ -0,0 +1,15 @@
+// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate="profile=pro_int,pro_fp extension=int16,int4,bf16,fp8e4m3,fp8e5m2,fft,variable,controlflow,doubleround,inexactround strict-op-spec-alignment" | FileCheck %s
+
+// -----
+
+// CHECK-LABEL: test_cond_if
+func.func @test_cond_if(%arg0: tensor<i8>, %arg1: tensor<i8>, %arg2: tensor<i1>) -> tensor<i8> {
+ %0 = tosa.cond_if %arg2 (%arg3 = %arg0, %arg4 = %arg1) : tensor<i1> (tensor<i8>, tensor<i8>) -> tensor<i8> {
+ ^bb0(%arg3: tensor<i8>, %arg4: tensor<i8>):
+ tosa.yield %arg3 : tensor<i8>
+ } else {
+ ^bb0(%arg3: tensor<i8>, %arg4: tensor<i8>):
+ tosa.yield %arg4 : tensor<i8>
+ }
+ return %0 : tensor<i8>
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/159754
More information about the Mlir-commits
mailing list