Skip to content

Commit f6a756f

Browse files
author
xiaohui1.xu
authored
[mlir][linalg] fix segmentation fault in isContractionBody function (#108703)
Fix Segmentation Fault in function. `getDefiningOp()` may return `nullptr` pointer.
1 parent f6dacda commit f6a756f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool mlir::linalg::detail::isContractionBody(
222222
Value contributed = getSourceSkipUnary(
223223
isa<BlockArgument>(reductionLHS) ? reductionRHS : reductionLHS);
224224
Operation *elementwiseOp = contributed.getDefiningOp();
225-
if (elementwiseOp->getNumResults() != 1 ||
225+
if (!elementwiseOp || elementwiseOp->getNumResults() != 1 ||
226226
elementwiseOp->getNumOperands() != 2) {
227227
errs << "expected elementwise op to be binary";
228228
return false;

mlir/test/Dialect/Linalg/match-ops-interpreter.mlir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,21 @@ module attributes { transform.target_tag = "start_here" } {
996996
} -> tensor<40x10x50x15xf32>
997997
return %result : tensor<40x10x50x15xf32>
998998
}
999+
1000+
func.func @generic_min(%arg0: tensor<1x7x4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<1x1x4xf32>) {
1001+
linalg.generic {
1002+
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1 * 2 + d3 * 2, d2)>,
1003+
affine_map<(d0, d1, d2, d3) -> (d3)>,
1004+
affine_map<(d0, d1, d2, d3) -> (d0, d1, d2)>],
1005+
iterator_types = ["parallel", "parallel", "parallel", "reduction"]}
1006+
ins(%arg0, %arg1 : tensor<1x7x4xf32>, tensor<4xf32>)
1007+
outs(%arg2 : tensor<1x1x4xf32>) {
1008+
^bb0(%in: f32, %in_1: f32, %out: f32):
1009+
%5 = arith.minimumf %out, %in : f32
1010+
linalg.yield %5 : f32
1011+
} -> tensor<1x1x4xf32>
1012+
return
1013+
}
9991014
}
10001015

10011016
// -----

0 commit comments

Comments
 (0)