Skip to content

Commit 8f9fc6c

Browse files
authored
[mlir][GPU] Add FunctionOpInterface check for OpToFuncCallLowering (#113449)
This PR adds a `FunctionOpInterface` check in `OpToFuncCallLowering` to resolve a crash when ops not in function. Fixes #113334.
1 parent ec2da0c commit 8f9fc6c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ struct OpToFuncCallLowering : public ConvertOpToLLVMPattern<SourceOp> {
6161
SourceOp>::value,
6262
"expected op with same operand and result types");
6363

64+
if (!op->template getParentOfType<FunctionOpInterface>()) {
65+
return rewriter.notifyMatchFailure(
66+
op, "expected op to be within a function region");
67+
}
68+
6469
SmallVector<Value, 1> castedOperands;
6570
for (Value operand : adaptor.getOperands())
6671
castedOperands.push_back(maybeCast(operand, rewriter));

mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -convert-math-to-rocdl -split-input-file | FileCheck %s
1+
// RUN: mlir-opt %s -convert-math-to-rocdl -allow-unregistered-dialect -split-input-file | FileCheck %s
22

33
module @test_module {
44
// CHECK: llvm.func @__ocml_fmod_f16(f16, f16) -> f16
@@ -481,3 +481,17 @@ module @test_module {
481481
func.return %resultf16, %resultf32, %resultf64, %resultbf16 : f16, f32, f64, bf16
482482
}
483483
}
484+
485+
// -----
486+
487+
// Math operation not inside function
488+
// Ensure it not crash
489+
490+
module {
491+
"test.some_op_with_region"() ({
492+
^bb0(%arg0: f64):
493+
// CHECK: math.atan
494+
%0 = math.atan %arg0 : f64
495+
"test.possible_terminator"() : () -> ()
496+
}) : () -> ()
497+
}

0 commit comments

Comments
 (0)