[Mlir-commits] [mlir] [mlir][GPU] Add FunctionOpInterface check for `OpToFuncCallLowering` (PR #113449)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 23 05:28:12 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-gpu
Author: Longsheng Mou (CoTinker)
<details>
<summary>Changes</summary>
This PR adds a `FunctionOpInterface` check in `OpToFuncCallLowering` to resolve a crash when ops not in function. Fixes #<!-- -->113334.
---
Full diff: https://github.com/llvm/llvm-project/pull/113449.diff
2 Files Affected:
- (modified) mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h (+5)
- (modified) mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir (+14)
``````````diff
diff --git a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
index 1cf8a1acb31935..3b94abd88f9ed2 100644
--- a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
+++ b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
@@ -61,6 +61,11 @@ struct OpToFuncCallLowering : public ConvertOpToLLVMPattern<SourceOp> {
SourceOp>::value,
"expected op with same operand and result types");
+ if (!op->template getParentOfType<FunctionOpInterface>()) {
+ return rewriter.notifyMatchFailure(
+ op, "expected op to be within a function region");
+ }
+
SmallVector<Value, 1> castedOperands;
for (Value operand : adaptor.getOperands())
castedOperands.push_back(maybeCast(operand, rewriter));
diff --git a/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir b/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
index ddd96bf797e6e7..c1b2407a66d915 100644
--- a/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
+++ b/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
@@ -481,3 +481,17 @@ module @test_module {
func.return %resultf16, %resultf32, %resultf64, %resultbf16 : f16, f32, f64, bf16
}
}
+
+// -----
+
+// Math operation not inside function
+// Ensure it not crash
+
+module {
+ "test.some_op_with_region"() ({
+ ^bb0(%arg0: f64):
+ // CHECK: math.atan
+ %0 = math.atan %arg0 : f64
+ "test.possible_terminator"() : () -> ()
+ }) : () -> ()
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/113449
More information about the Mlir-commits
mailing list