diff --git a/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc b/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc index cba8a52..4d44b9c 100644 --- a/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc +++ b/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc @@ -131,6 +131,7 @@ class PointwiseToLinalgConverter : public OpConversionPattern { SmallVector indexing_maps(args.size() + (isLHLO ? 0 : 1), common_indexing_map); + bool failed = false; auto linalg_op = rewriter.create( loc, op_result_types, inputs, output_buffers, /*initTensors=*/ValueRange{}, indexing_maps, @@ -141,8 +142,13 @@ class PointwiseToLinalgConverter : public OpConversionPattern { Value op_result = lmhlo::HloOpToStdScalarOp::map( op, body_result_types, llvm::to_vector<2>(args.take_front(inputs.size())), &rewriter); - nested_builder.create(loc, op_result); + if (op_result == nullptr) { + failed = true; + } else { + nested_builder.create(loc, op_result); + } }); + if (failed) return failure(); rewriter.replaceOp(op, linalg_op.getOperation()->getResults()); return success(); }