Skip to content

Commit 9bf7023

Browse files
raikonenfnukuhar
andauthored
[mlir][linalg] fix indexOp folder to work in genericOp build with createOrFold (llvm#137427)
Currently in torch-mlir, indexOp folder is segfaulting when we call createOrFold in a genericOp builder. (*this)->getParentOp ended up with null which is causing the issue. This is seen in poolSizeCalculator.getPoolSize being called from createAvgPoolValueCountIncludePadFalseCase. link: https://github.com/llvm/torch-mlir/blob/80a3dfddd341c72ab9bd6c6688b872bf3a5e4ddb/lib/Conversion/TorchToLinalg/Pooling.cpp#L918-L921 --------- Signed-off-by: Stanley Winata <[email protected]> Co-authored-by: Jakub Kuderski <[email protected]>
1 parent a8b2c96 commit 9bf7023

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,12 @@ LogicalResult IndexOp::verify() {
22842284
}
22852285

22862286
OpFoldResult IndexOp::fold(FoldAdaptor adaptor) {
2287-
auto linalgOp = cast<LinalgOp>((*this)->getParentOp());
2287+
auto linalgOp = dyn_cast_or_null<LinalgOp>((*this)->getParentOp());
2288+
// Bail out if `linalg.index` does not have a proper parent yet at this
2289+
// point, e.g., when calling `createOrFold` during IR construction in
2290+
// `genericOp::build`.
2291+
if (!linalgOp)
2292+
return OpFoldResult{};
22882293

22892294
// Index of unit dims is always 0.
22902295
SmallVector<int64_t, 4> loopBounds = linalgOp.getStaticLoopRanges();

0 commit comments

Comments
 (0)