diff --git a/enzyme/Enzyme/MLIR/Passes/EnzymeMLIRPass.cpp b/enzyme/Enzyme/MLIR/Passes/EnzymeMLIRPass.cpp index c3fe53a7c4e..d83532db35a 100644 --- a/enzyme/Enzyme/MLIR/Passes/EnzymeMLIRPass.cpp +++ b/enzyme/Enzyme/MLIR/Passes/EnzymeMLIRPass.cpp @@ -157,6 +157,11 @@ struct DifferentiatePass : public DifferentiatePassBase { OpBuilder builder(CI); auto dCI = builder.create(CI.getLoc(), newFunc.getName(), newFunc.getResultTypes(), args); + if (dCI.getNumResults() != CI.getNumResults()) { + CI.emitError() << "Incorrect number of results for enzyme operation: " + << *CI << " expected " << *dCI; + return failure(); + } CI.replaceAllUsesWith(dCI); CI->erase(); return success();