Skip to content

[mlir] fix crash in transform.print verification #86679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024
Merged

Conversation

ftynse
Copy link
Member

@ftynse ftynse commented Mar 26, 2024

Transform op trait verification calls getEffects, and since trait verification runs before op verification, this call cannot assume the op to be valid. However, the operand getters now return a TypedValue that unconditionally casts the value to the expected type, leading to an assertion failure. Use the untyped mechanism instead.

Fixes #84701.

Transform op trait verification calls `getEffects`, and since trait
verification runs before op verification, this call cannot assume the op
to be valid. However, the operand getters now return a `TypedValue` that
unconditionally casts the value to the expected type, leading to an
assertion failure. Use the untyped mechanism instead.

Fixes llvm#84701.
@llvmbot
Copy link
Member

llvmbot commented Mar 26, 2024

@llvm/pr-subscribers-mlir

Author: Oleksandr "Alex" Zinenko (ftynse)

Changes

Transform op trait verification calls getEffects, and since trait verification runs before op verification, this call cannot assume the op to be valid. However, the operand getters now return a TypedValue that unconditionally casts the value to the expected type, leading to an assertion failure. Use the untyped mechanism instead.

Fixes #84701.


Full diff: https://github.com/llvm/llvm-project/pull/86679.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/Transform/IR/TransformOps.cpp (+5-1)
  • (modified) mlir/test/Dialect/Transform/ops-invalid.mlir (+11)
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index 8d2ed8f6d73714..abd557a508a103 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -2628,7 +2628,11 @@ transform::PrintOp::apply(transform::TransformRewriter &rewriter,
 
 void transform::PrintOp::getEffects(
     SmallVectorImpl<MemoryEffects::EffectInstance> &effects) {
-  onlyReadsHandle(getTarget(), effects);
+  // We don't really care about mutability here, but `getTarget` now
+  // unconditionally casts to a specific type before verification could run
+  // here.
+  if (!getTargetMutable().empty())
+    onlyReadsHandle(getTargetMutable()[0].get(), effects);
   onlyReadsPayload(effects);
 
   // There is no resource for stderr file descriptor, so just declare print
diff --git a/mlir/test/Dialect/Transform/ops-invalid.mlir b/mlir/test/Dialect/Transform/ops-invalid.mlir
index 73a5f36af92952..cc04e65420c5b7 100644
--- a/mlir/test/Dialect/Transform/ops-invalid.mlir
+++ b/mlir/test/Dialect/Transform/ops-invalid.mlir
@@ -771,3 +771,14 @@ module attributes { transform.with_named_sequence } {
     transform.yield %arg0 : !transform.any_op
   }
 }
+
+// -----
+
+module attributes { transform.with_named_sequence } {
+  transform.named_sequence @match_matmul(%entry: !transform.any_op) -> () {
+    %c3 = transform.param.constant 1 : i64 -> !transform.param<i64>
+    // expected-error @below {{op operand #0 must be TransformHandleTypeInterface instance}}
+    transform.print %c3 : !transform.param<i64>
+    transform.yield
+  }
+}

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ftynse! Would it be feasible to actually support printing types and params?

@ftynse
Copy link
Member Author

ftynse commented Mar 26, 2024

We have this: https://mlir.llvm.org/docs/Dialects/Transform/#transformdebugemit_param_as_remark-transformdebugemitparamasremarkop.

Types are justs a param that holds a TypeAttr AFAIU so it should work, let me know if it does not.

@ftynse ftynse merged commit fa1b807 into llvm:main Mar 27, 2024
@ftynse ftynse deleted the fix-84701 branch March 27, 2024 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mlir][transform] Printing transform.param<i64> crashes verifier
5 participants