diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorMaskElimination.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorMaskElimination.cpp index 8a181a429e41c..6f75ce7a04511 100644 --- a/mlir/lib/Dialect/Vector/Transforms/VectorMaskElimination.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorMaskElimination.cpp @@ -99,6 +99,10 @@ void eliminateVectorMasks(IRRewriter &rewriter, FunctionOpInterface function, if (!vscaleRange) return; + // Early exit for functions without a body. + if (function.isExternal()) + return; + OpBuilder::InsertionGuard g(rewriter); // Build worklist so we can safely insert new ops in diff --git a/mlir/test/Dialect/Vector/eliminate-masks.mlir b/mlir/test/Dialect/Vector/eliminate-masks.mlir index 0b78687fb9832..88be7e529bb9e 100644 --- a/mlir/test/Dialect/Vector/eliminate-masks.mlir +++ b/mlir/test/Dialect/Vector/eliminate-masks.mlir @@ -45,6 +45,12 @@ func.func @eliminate_redundant_masks_through_insert_and_extracts(%tensor: tensor // ----- +// Test to ensure that functions without a body are skipped. +// CHECK-LABEL: func.func private @negative_no_func_body() +func.func private @negative_no_func_body() + +// ----- + // CHECK-LABEL: @negative_extract_slice_size_shrink // CHECK-NOT: vector.constant_mask // CHECK: %[[MASK:.*]] = vector.create_mask